标签:blog http io for 2014 问题 amp log
// 动态规划求最少钱币枚数
#include <stdio.h>
int a[20],c[20][3000],k,n;
int min(int x,int y)
{ return x>y?y:x; }
int main()
{ int i,j;
scanf("%d",&k);
for (i=0; i<k; i++) scanf("%d",&a[i]);
scanf("%d",&n);
for (j=0; j<=n; j++) c[0][j]=j;
for (i=1;i<k; i++)
for (j=0;j<=n;j++)
if ( j>=a[i] )
c[i][j]=min( c[i-1][j], c[i][j-a[i]]+1);
else c[i][j]=c[i-1][j];
printf("%d\n",c[k-1][n]);
}
标签:blog http io for 2014 问题 amp log
原文地址:http://www.cnblogs.com/2014acm/p/3908430.html