文章
11
粉丝
406
获赞
3
访问
84.9k
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
int m,n,*arr,res;
void backtrace(int now,int rest, int Nowres){
if(rest==0){
res=(Nowres<res)?Nowres:res;
return;
}
for(int i=now;i<n;++i){
if(rest>=arr[i]){
backtrace(i+1,rest-arr[i],Nowres+1);
}
}
}
int main(){
while(~scanf("%d%d",&m,&n)){
arr=new int[n];
for(int i=n-1;i>=0;--i)scanf("%d",&arr[i]);
res=n+1;
backtrace(0,m,0);
(res==n+1)?printf("%d\n",0):printf("%d\n",res);
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发