bzoj 4145: [AMPPZ2014]The Prices【状压dp】
2018-10-25 08:13
399 查看
设f[s][i]为已经买了集合s,当前在商店i,转移的话就是枚举新买的物品,两种情况,一种是在原商店买,不用付路费,另一种是从其他商店过来,这种再枚举从那个商店过来是不行的,记一个mn[s]为已经买了集合s的最小代价,直接用这个转移第二种情况即可
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=105; int n,m,b ,d ,a ,f[(1<<16)+5] ,mn[(1<<16)+5],ans=1e9; int main() { scanf("%d%d",&n,&m); b[0]=1; for(int i=1;i<=m;i++) b[i]=b[i-1]<<1; for(int i=1;i<=n;i++) { scanf("%d",&d[i]); for(int j=1;j<=m;j++) scanf("%d",&a[i][j]); } memset(f,0x3f,sizeof(f)); memset(mn,0x3f,sizeof(mn)); for(int i=1;i<=n;i++) f[0][i]=d[i],mn[0]=min(mn[0],d[i]); for(int s=1;s<b[m];s++) for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) if(s&b[j-1]) f[s][i]=min(f[s][i],min(f[s^b[j-1]][i]+a[i][j],mn[s^b[j-1]]+d[i]+a[i][j])); mn[s]=min(mn[s],f[s][i]); } for(int i=1;i<=n;i++) ans=min(ans,f[(1<<m)-1][i]); printf("%d\n",ans); return 0; }
相关文章推荐
- bzoj 4145: [AMPPZ2014]The Prices 状压dp
- BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )
- BZOJ 4145: [AMPPZ2014]The Prices
- 4145: [AMPPZ2014]The Prices
- bzoj4145 AMPPZ2014 The Prices 状压dp
- 4145: [AMPPZ2014]The Prices 状压DP
- 【BZOJ4145】[AMPPZ2014]The Prices【状压DP】【背包】
- 【BZOJ4145】[AMPPZ2014]The Prices 状压DP
- 【bzoj4145】【AMPPZ2014】【The Prices】【状压dp】
- [BZOJ]4151: [AMPPZ2014]The Cave
- BZOJ 4145 AMPPZ2014 The Prices 状压DP
- BZOJ 4152: [AMPPZ2014]The Captain 分层图最短路
- 【bzoj4145】[AMPPZ2014]The Prices
- 【AMPPZ2014】【BZOJ4145】The Prices
- 【BZOJ 4148】 4148: [AMPPZ2014]Pillars (乱搞)
- BZOJ 4152: [AMPPZ2014]The Captain(最短路)
- 循环队列+堆优化dijkstra最短路 BZOJ 4152: [AMPPZ2014]The Captain
- BZOJ 4143: [AMPPZ2014]The Lawyer( sort )
- 【BZOJ】【4145】【AMPPZ2014】The Prices
- Bzoj 4147: [AMPPZ2014]Euclidean Nim(博弈)