uva 357 - Let Me Count The Ways

来源:互联网 发布:python time sleep作用 编辑:程序博客网 时间:2024/05/17 06:50
#include <cstdio>#include <cstring>#include <cctype>#include <cstdlib>#include <queue>#include <stack>#include <cmath>#include <string>#include <iostream>#include <algorithm>using namespace std;#define maxn 30000 + 10#define INF 2100000000#define ll long longint v[8] = {1, 5, 10, 25, 50};ll dp[8][maxn];ll DP(int i, int j){    if(dp[i][j] != -1) return dp[i][j];    dp[i][j] = 0;    for(int k = 0; j - k * v[i] >= 0; ++k)        dp[i][j] += DP(i-1, j-k*v[i]);    return dp[i][j];}int main(){    int n;    memset(dp, -1, sizeof(dp));    while(scanf("%d", &n) != EOF)    {        for(int i = 0; i <= n; ++i)            dp[0][i] = 1;//用前i种钱组成j        ll ans = DP(4, n);        if(ans == 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", ans, n);    }    return 0;}

0 0
原创粉丝点击