HDU 1284 钱币兑换问题 完全背包

来源:互联网 发布:mybatis log4j 打印sql 编辑:程序博客网 时间:2024/05/04 07:01

传送门:HDU 1284 钱币兑换问题

分析:
本题 完全背包 模版。详情见注释。

代码如下:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define ms(x, y) memset(x, y, sizeof(x))const double PI = acos(-1.0), eps = 1e-8;int dp[32769],n,i,j;int main() {    dp[0] = 1;    // 完全背包打表    for(int i=1; i<4; i++)        for(int j=i; j<32769; j++)            dp[j] += dp[j-i];  // 状态转移(dp[]数组在不同的遍历阶段进行了更新 1 2 3 种硬币 正好对应了 1 2 3 分的价值)    while(scanf("%d",&n) != EOF)        printf("%d\n",dp[n]);    return 0;}
1 0
原创粉丝点击