如题
#include<iostream>
#include<cstdio>
using namespace std;
int t,m;
bool vis[1010]={0};
int at[1010],ap[1010];
int push[1010];
int maxn=-1;
void dfs(int tt,int pp,int top){
maxn=max(maxn,pp);
if(tt>t){
return;
}
for(int j=top+1;j<m;j++){
if(!vis[j]&&tt+at[j]<=t){
vis[j]=1;
dfs(tt+at[j],pp+ap[j],j);
vis[j]=0;
}else{
maxn=max(maxn,pp);
}
}
return;
}
int main(){
scanf("%d%d",&t,&m);
for(int i=0;i<m;i++){
scanf("%d%d",&at[i],&ap[i]);
}
dfs(0,0,-1);
cout<<maxn<<endl;
return 0;
}