标签:ofo space isp color void 暴力 技术 src ref
http://172.20.6.3/Problem_Show.asp?id=1382
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 const int maxn=1<<16; 8 int n; 9 int a[maxn+10]={}; 10 int f[maxn+10]={},tot; 11 int vis[20]={}; 12 void dfs(int k,int num,int mm){ 13 if(k<=0){ 14 f[mm]=max(f[mm],f[mm-num]+f[num]); 15 return; 16 } 17 int x=1<<(vis[k]-1); 18 dfs(k-1,num,mm); 19 dfs(k-1,num+x,mm); 20 } 21 int main(){ 22 scanf("%d",&n); 23 int ma=1<<n; 24 for(int i=1;i<ma;i++){ 25 scanf("%d",&a[i]); 26 f[i]=a[i]; 27 }int x1; 28 for(int i=1;i<ma;i++){ 29 tot=0; 30 for(int j=1;j<=n;j++){ 31 x1=1<<(j-1); 32 if((x1|i)==i)vis[++tot]=j; 33 } 34 dfs(tot,0,i); 35 } 36 cout<<f[ma-1]<<endl; 37 return 0; 38 }
标签:ofo space isp color void 暴力 技术 src ref
原文地址:http://www.cnblogs.com/137shoebills/p/7787023.html