题意:有n个人写m行代码,第i个人写一行代码会产生ai个bug,问bug小于b的方案数
思路:背包二维费用
AC代码:
#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #define ll long long #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a) memset(a,0,sizeof(a)) #define mp(x,y) make_pair(x,y) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e5+100; ll n,m,b,mod,dp[505][505]={1}; int a[505]; int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m>>b>>mod; for(int i=1; i<=n; ++i){ cin>>a[i]; } for(int i=1; i<=n; ++i) for(int k=1; k<=m; ++k){ for(int j=a[i]; j<=b; ++j){ dp[k][j]=dp[k-1][j-a[i]]+dp[k][j]; dp[k][j]%=mod; } } ll ans=0; for(int i=0; i<=b; ++i){ ans+=dp[m][i]; ans%=mod; } cout<<(ans+mod)%mod<<endl; return 0; }