//Hello. I‘m Peter.
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define MAXN
#define N 505
#define M
int dp[N][N],n,m,mod,b,a[N];
int main(){
cin>>n>>m>>b>>mod;
for(int i=0;i<n;i++){
scanf("%d",a+i);
}
dp[0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
for(int k=0;k<=b;k++){
if(k+a[i]>b||!dp[j][k]) continue;
dp[j+1][k+a[i]]+=dp[j][k];
if(dp[j+1][k+a[i]]>=mod) dp[j+1][k+a[i]]-=mod;
}
}
}
int ans=0;
for(int k=0;k<=b;k++){
ans+=dp[m][k];
if(ans>=mod) ans-=mod;
}
printf("%d\n",ans);
return 0;
}
Codeforces Round #302 (Div. 1 A)
原文地址:http://blog.csdn.net/uestc_peterpan/article/details/45579643