Nanyang Institute of Technology ACM Dole race cum 16 retired Memorial E sequence operation Ⅰ

Topic Source: http://acm.nyist.edu.cn/problem/1665

Subject description:

Given a positive integer of length N sequence A1, A2, AN, to choose the number of the plurality, and that their is M, ask how many there are options.

Enter a description:

The first line is the two numbers represents N and M.
The second line is the number of N.
1 <= N <= 100, 1 <= M <= 10 ^ 5, 1 <= A_i <= 1000.

Output Description:

A number that is M and the number of combinations.

Sample input:
4 4
1 1 2 2
Sample output:
3

Naked 01 backpack

Reference Code:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#define ll long long int
const int N=1e3+5;
#define inf 0x3f3f3f3f
#define endl "\n"
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
ll n,m,a[N],dp[N];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    dp[0]=1;
    for(int i=1;i<=n;i++){
        for(int j=m;j>=a[i];j--){
            dp[j]=dp[j-a[i]]+dp[j];
        }
    }
    cout<<dp[m]<<endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/nuoyanli/article/details/92446836