poj 2923 状态压缩dp
2017-04-20 15:15
246 查看
#include<cstdio> #include<cstring> #define MAX(x,y) ((x)>(y)?(x):(y)) #define MIN(x,y) ((x)>(y)?(y):(x)) #define INF 0x3f3f3f3f int dp[1025]; int vis[1025],w[105],d[1025]; int n,c1,c2; int judge(int x) { int sum=0; memset(vis,0,sizeof(vis)); vis[0]=1; for(int k=0;k<n;k++) { if((1<<k)&x) { sum+=w[k]; if(sum>c1+c2) return 0; for(int j=c1;j>=w[k];j--) if(vis[j-w[k]]) vis[j]=1; } } for(int i=c1;i>=0;i--) if(vis[i]&&sum-i<=c2) return 1; return 0; } int main() { int T,tot,t=1; scanf("%d",&T); while(T--) { dp[0]=0; scanf("%d%d%d",&n,&c1,&c2); for(int i=0;i<n;i++) scanf("%d",&w[i]); tot=0; for(int i=0;i<(1<<n);i++) if(judge(i)) d[tot++]=i; memset(dp,0x3f,sizeof(dp)); dp[0]=0; for(int i=0;i<tot;i++) { for(int j=((1<<n)-1);j>=0;j--) if(dp[j]!=INF) { if(j&d[i]) continue; dp[d[i]|j]=MIN(dp[j]+1,dp[d[i]|j]); } } printf("Scenario #%d:\n%d\n\n",t++,dp[(1<<n)-1]); } }
相关文章推荐
- poj 2923(状态压缩dp)
- POJ 2923 Relocation(状态压缩 + 两次DP)
- POJ 2923 dp 状态压缩
- poj 2923 dp状态压缩+背包(两辆货车来运货)
- 状态压缩DP——POJ 2923
- POJ 2923 Relocation(状态压缩DP)
- POJ 2923 Relocation / 状态压缩DP
- POJ 2923 Relocation(01背包变形, 状态压缩DP)
- POJ 2923 Relocation(状态压缩DP+DP:01背包)
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ 1185 炮兵阵地 状态压缩(DP)
- POJ 2404 Jogging Trails (中国邮递员问题,状态压缩DP)
- POJ 2411 Mondriaan's Dream 状态压缩dp
- POJ 2817 WordStack(状态压缩DP)
- 【状态压缩DP】POJ 1170
- POJ 2411 Mondriaan's Dream 状态压缩DP
- poj 2411 状态压缩DP 铺砖块
- POJ 3254 Corn Fields【状态压缩DP】
- POJ 3254 Corn Fields 状态压缩DP
- POJ 1185 炮兵阵地 状态压缩DP