zoukankan      html  css  js  c++  java
  • OpenJudge Bailian 2755 神奇的口袋 DP

    神奇的口袋
    Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Description

    有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40。John现在有n个想要得到的物品,每个物品的体积分别是a 1,a 2……a n。John可以从这些物品中选择一些,如果选出的物体的总体积是40,那么利用这个神奇的口袋,John就可以得到这些物品。现在的问题是,John有多少种不同的选择物品的方式。

    Input

    输入的第一行是正整数n (1 <= n <= 20),表示不同的物品的数目。接下来的n行,每行有一个1到40之间的正整数,分别给出a1,a 2……a n的值。

    Output

    输出不同的选择物品的方式的数目。

    Sample Input

    3
    20
    20
    20
    

    Sample Output

    3


    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int,int> PII;
    
    int a[25];
    int dp[100][100];
    
    int main()
    {
        //FIN
        int n;
        while(~scanf("%d", &n)){
            for(int i = 1; i <= n; i ++){
                scanf("%d", &a[i]);
                dp[i][0] = 1;
            }
            dp[0][0] = 1;
            for(int i = 1; i <= n; i ++){
                for(int j = 1; j <= 40; j ++){
                    dp[i][j] = dp[i - 1][j];
                    if(j >= a[i]){
                        dp[i][j] += dp[i - 1][j - a[i]];
                    }
                }
            }
            printf("%d
    ", dp[n][40]);
    
        }
    }
    

      

  • 相关阅读:
    poj1703--Find them, Catch them
    poj2828--Buy Tickets
    POJ 2594 Treasure Exploration(Floyd+最小路径覆盖)
    HDU
    二分图的一些性质
    HDU
    POJ 1659 Frogs' Neighborhood (Havel定理构造图)
    HDU
    HDU
    2018 Multi-University Training Contest 1
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5790950.html
Copyright © 2011-2022 走看看