题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284
解析:懵逼啊,明明会多重背包,为什么比赛时想不起来,知道是DP一直不知道找状态方程,还是自己太菜
代码:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<vector> #include<queue> #include<map> #include<cmath> #define N 50009 using namespace std; const int INF = 0x3f3f3f3f; int dp[N]; void init() { memset(dp, 0, sizeof(dp)); dp[0] = 1; // fanganshu for(int i = 1; i <= 3; i++) { for(int j = i; j <= 33000; j++) dp[j] += dp[j - i]; } } int main() { init(); int n; while(~scanf("%d", &n)) printf("%d\n", dp[n]); return 0; }