uva 357 Let Me Count The Ways

来源:互联网 发布:战争雷霆pw42数据 编辑:程序博客网 时间:2024/05/01 21:53

简单dp ,水题


#include <iostream>#include <cstring>#include <cstdio>using namespace std;int n;int d[] = {1,5,10,25,50};long long dp[30010];int main(){memset(dp,0,sizeof(dp));dp[0] = 1;for(int i=0;i<5;i++){for(int j=0;j+d[i]<=30000;j++){dp[j+d[i]] += dp[j];}}while(cin >> n){if(dp[n]==1) printf("There is only 1 way to produce %d cents change.\n",n);else printf("There are %lld ways to produce %d cents change.\n",dp[n],n);}return 0;} 


0 0