标签:查询 view play 最小 color exit namespace dig pac
1 #include<cstdio> 2 #include<cstdlib> 3 #include<algorithm> 4 #include<cstring> 5 #include<ctype.h> 6 using namespace std; 7 int f[50][50]; 8 int n,m,k,w[50],ans,tot; 9 10 template<typename T> 11 void read(T &x) { 12 char tt; 13 bool flag=0; 14 while(!isdigit(tt=getchar())&&tt!=‘-‘); 15 tt==‘-‘?(x=0,flag=1):(x=tt-‘0‘); 16 while(isdigit(tt=getchar())) x=x*10+tt-‘0‘; 17 } 18 19 20 void dfs(int num,int now,int x) { 21 ++tot; 22 ans=max(ans,x); 23 if(tot>100000000) return; 24 if(now>k) return; 25 if(num+1<=n&&x+w[now]<=m) dfs(num+1,now+1,x+w[now]); 26 dfs(num,now+1,x); 27 } 28 int cmp(int a,int b) { 29 return a>b; 30 } 31 int main() { 32 read(n),read(m); 33 read(k); 34 for(int i=1; i<=k; i++) read(w[i]); 35 sort(w+1,w+k+1,cmp); 36 int s=0; 37 for(int i=1; i<=n; i++) s+=w[i]; 38 if(s<=m) printf("%d\n",s),exit(0); 39 dfs(0,1,0); 40 printf("%d\n",ans); 41 }
标签:查询 view play 最小 color exit namespace dig pac
原文地址:https://www.cnblogs.com/KatouKatou/p/9526049.html