ZOJ 1163 The Staircases / 01背包

来源:互联网 发布:网络教育高起专 编辑:程序博客网 时间:2024/05/17 22:45

每个物品选一次 01背包

#include <cstdio>#include <cstring>const int maxn = 510;double dp[maxn];int main(){memset(dp, 0 ,sizeof(dp));dp[0] = 1;for(int i = 1; i <= 500; i++){for(int j = 500; j >= i; j--){dp[j] += dp[j-i];}}int n;while(scanf("%d", &n) && n){printf("%.0f\n", dp[n]-1);}return 0;}


 

0 0