标签:memory script inf http can status enter log sam
一道裸的状态压缩动态规划
1 #include<cstdio> 2 #define mxn 17 3 #define inf (1E9) 4 #define mxb (1<<17) 5 #define bit(x) (1<<(x)) 6 #define max(a,b) (a>b?a:b) 7 #define min(a,b) (a<b?a:b) 8 int n,m; 9 int t[mxb]; 10 int w[mxb]; 11 int f[mxb]; 12 main(){ 13 scanf("%d%d",&m,&n); 14 for(int i=0;i<n;++i) 15 scanf("%d%d",t+bit(i),w+bit(i)); 16 for(int i=1,j;i<bit(n);++i)if(j=i&-i,j!=i) 17 t[i]=max(t[j],t[i^j]),w[i]=w[j]+w[i^j]; 18 for(int i=1,j;i<bit(n);++i) 19 for(f[i]=inf,j=i;j;j=(j-1)&i) 20 if(w[j]<=m)f[i]=min(f[i],f[i^j]+t[j]); 21 printf("%d\n",f[bit(n)-1]); 22 }
@Author: YouSiki
标签:memory script inf http can status enter log sam
原文地址:http://www.cnblogs.com/yousiki/p/6534868.html