题意分析
裸地01背包
因为数组开小了WA了一万年
代码总览
#include<bits/stdc++.h>
using namespace std;
const int nmax = 105;
int c[nmax],v[nmax];
int dp[nmax][1005];
int totime,m;
int main(){
while(scanf("%d %d",&totime,&m)!=EOF){
memset(c,0,sizeof c);
memset(v,0,sizeof v);
memset(dp,0,sizeof dp);
for(int i = 1;i<=m;++i){
scanf("%d",&c[i]);
scanf("%d",&v[i]);
}
for(int i = 1;i<=m;++i){
for(int j = 1;j<=totime;++j){
dp[i][j] = dp[i-1][j];
if(j-c[i] >=0) dp[i][j] = max(dp[i][j], dp[i-1][j-c[i]] + v[i]);
}
}
printf("%d\n",dp[m][totime]);
}
return 0;
}