【AMPPZ2014】【BZOJ4145】The Prices
来源:互联网 发布:jsp网上报名系统源码 编辑:程序博客网 时间:2024/06/06 01:21
Description
你要购买m种物品各一件,一共有n家商店,你到第i家商店的路费为d[i],在第i家商店购买第j种物品的费用为c[i][j],
求最小总费用。
Input
第一行包含两个正整数n,m(1<=n<=100,1<=m<=16),表示商店数和物品数。
接下来n行,每行第一个正整数di表示到第i家商店的路费,接下来m个正整数,
依次表示c[i]j。
Output
一个正整数,即最小总费用。
Sample Input
3 4
5 7 3 7 9
2 1 20 3 2
8 1 20 1 1
Sample Output
16
HINT
在第一家店买2号物品,在第二家店买剩下的物品。
Source
鸣谢Claris上传
物品种类非常少,所以可以考虑二进制表示物品状态
然后建两个数组DP,一个表示在一个店里买某些物品的价格,一个是在所有店的
第一个很好求.
第二个可以对每个物品状态用它和它的补集这样的关系来更新
然而我最早一直想写网络流
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define MAXN 110#define GET (ch>='0'&&ch<='9')using namespace std;int n,m;int c[MAXN][MAXN],d[MAXN];int f[1<<17],g[1<<17];void in(int &x){ char ch=getchar();x=0;int flag=1; while (!GET) flag=ch=='-'?-1:flag,ch=getchar(); while (GET) x=x*10+ch-'0',ch=getchar();x*=flag;}void dfs(int id,int x,int sum,int S){ f[S]=min(f[S],sum); for (int i=x;i<m;i++) dfs(id,i+1,sum+c[id][i+1],S|(1<<i));}int main(){ in(n);in(m);memset(f,0x3f,sizeof(f));f[0]=0; for (int i=1;i<=n;i++) { in(d[i]); for (int j=1;j<=m;j++) in(c[i][j]); dfs(i,0,d[i],0); } for (int i=1;i<(1<<m);i++) { g[i]=0x7fffffff; for (int j=i;j;j=(j-1)&i) g[i]=min(g[i],f[j]+g[i^j]); } printf("%d\n",g[(1<<m)-1]);}
0 0
- 【bzoj4145】[AMPPZ2014]The Prices
- 【AMPPZ2014】【BZOJ4145】The Prices
- [BZOJ4145] [AMPPZ2014]The Prices
- bzoj4145 [AMPPZ2014]The Prices
- [bzoj4145][AMPPZ2014]The Prices
- BZOJ4145: [AMPPZ2014]The Prices
- 【bzoj4145】【AMPPZ2014】【The Prices】【状压dp】
- 【BZOJ4145】[AMPPZ2014]The Prices【状压DP】【背包】
- bzoj4145 [AMPPZ2014]The Prices 状压dp
- bzoj4145 [AMPPZ2014]The Prices (状压DP)
- BZOJ 4145: [AMPPZ2014]The Prices
- 【BZOJ4145】【装压DP】 The Prices 题解
- BZOJ 4145 AMPPZ2014 The Prices 状压DP
- 4145: [AMPPZ2014]The Prices 状压DP
- bzoj 4145 [AMPPZ2014]The Prices dp
- bzoj 4145: [AMPPZ2014]The Prices 状压dp
- 【AMPPZ2014】【BZOJ4143】The Lawyer
- 【bzoj4143】[AMPPZ2014]The Lawyer
- markdown编辑器使用
- 《Android 疯狂讲义》下载
- Mysql-ibatis 自动生成主键(selectKey)
- Collections.sort()方法排序对象
- freescale-imx6solo学习笔记
- 【AMPPZ2014】【BZOJ4145】The Prices
- 解决iOS9 下面微信不能调用的问题
- 又发现一个很好的ios博客--颐和园
- 今天开始在虚拟机上学习Linux
- SVN的使用
- redis 主从设置
- Mysql函数Last_insert_id()的真正含义
- 【数据库】PostgreSQL与MySQL比较
- 解决eclipse中出现Resource is out of sync with the file system问题