UVA 357 Let Me Count The Ways

来源:互联网 发布:表白视频制作软件 编辑:程序博客网 时间:2024/05/16 23:51

背包变形。

#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <string>using namespace std;typedef unsigned long long ULL;const int MAXN = 30010;const int INF = 0x3f3f3f3f;ULL f[30010];int n, C;int V[] = {0, 50, 25, 10, 5, 1};void init(){memset(f, 0, sizeof(f));f[0] = 1;n = 5;}ULL sum(ULL a, ULL b){return a+b;}void dp(){for(int i = 1; i <= n; i++){for(int v = V[i]; v <= C; v++){f[v] = sum(f[v], f[v-V[i]]);}}if(f[C] > 1){printf("There are %llu ways to produce %d cents change.\n", f[C], C);}else printf("There is only 1 way to produce %d cents change.\n", C);}void solve(){init();dp();}int main(){while(~scanf("%d", &C)){solve();}return 0;}


原创粉丝点击