P1855 榨取kkksc03
[Aimee](P1855 榨取kkksc03)
很简单的dp
#include<iostream>
#include<cstring>
using namespace std;
int n,m,t;
int mi[1000];
int ti[1000];
int dp[201][301][201];
int ans;
int dfs(int mon,int tim,int k){
if(mon>m||tim>t)
return -1;
if(dp[k][mon][tim]!=-1)
return dp[k][mon][tim];
if(k>n){
return 0;
}
return dp[k][mon][tim]=max(dfs(mon+mi[k],tim+ti[k],k+1)+1,dfs(mon,tim,k+1));
}
int main(){
cin>>n>>m>>t;
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;++i)
cin>>mi[i]>>ti[i];
cout<<dfs(0,0,1);
return 0;
}