Headmaster's Headache UVA10817
来源:互联网 发布:263视频会议登录软件 编辑:程序博客网 时间:2024/05/22 14:47
不等不说这道题其实是一个背包类似物
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <queue>#include <algorithm>#include <vector>#include <cstring>#include <stack>#include <cctype>#include <utility> #include <map>#include <string> #include <climits> #include <set>#include <string> #include <sstream>#include <utility>#include <ctime> using std::priority_queue;using std::vector;using std::swap;using std::stack;using std::sort;using std::max;using std::min;using std::pair;using std::map;using std::string;using std::cin;using std::cout;using std::set;using std::queue;using std::string;using std::istringstream;using std::make_pair;using std::greater;using std::endl;const int INFI(INT_MAX-100000);int table[1 << 8][1 << 8];int cost[110], state[110];int main(){int s;while(scanf("%d", &s), s){for(int i = 0; i < (1 << s); ++i)for(int j = 0; j < (1 << s); ++j)table[i][j] = INFI;int m, n;scanf("%d%d", &m, &n);int tw, fc = 0;int st1 = 0, st2 = 0;for(int i = 1; i <= m; ++i){scanf("%d", &tw);fc += tw;char tc = getchar();while(tc != '\n'){if(!isdigit(tc)){tc = getchar();continue;}int temp = 0;while(isdigit(tc)){temp *= 10;temp += tc-'0';tc = getchar();}--temp;if(st1&(1 << temp))st2 |= 1 << temp;elsest1 |= 1 << temp;}}table[st1][st2] = fc;for(int i = 1; i <= n; ++i){scanf("%d", cost+i);state[i] = 0;char tc = getchar();while(tc != '\n'){if(!isdigit(tc)){tc = getchar();continue;}int temp = 0;while(isdigit(tc)){temp *= 10;temp += tc-'0';tc = getchar();}--temp;state[i] |= 1 << temp;}}for(int i = 1; i <= n; ++i){int ts1, ts2;for(int j = (1 << s)-1; j >= 0; --j)for(int k = (1 << s)-1; k >= 0; --k)if(table[j][k] < INFI){ts1 = j|state[i];ts2 = (j&state[i])|k;table[ts1][ts2] = min(table[ts1][ts2], table[j][k]+cost[i]);}}printf("%d\n", table[(1 << s)-1][(1 << s)-1]);}return 0;}
- Headmaster's Headache UVA10817
- UVA10817 Headmaster's Headache
- UVa10817 Headmaster's Headache
- UVa10817 - Headmaster's Headache
- UVA10817 - Headmaster's Headache
- uva10817 Headmaster's Headache
- UVa10817 Headmaster's Headache
- uva10817 - Headmaster's Headache(01背包)
- [UVA10817] Headmaster's Headache && 状压DP
- 【 状压DP】 [UVA10817] Headmaster's Headache
- UVA10817 Headmaster's Headache dp+二进制集合
- UVa10817 Headmaster's headache[状压DP]
- UVA10817:Headmaster's Headache(状压dp)
- UVA10817 Headmaster's Headache 状态压缩的01背包
- UVA10817[Headmaster's Headache] 状态压缩动态规划
- UVA10817-----Headmaster's Headache-----状态压缩的背包(记忆化搜索实现)
- 10817 - Headmaster's Headache
- 10817 - Headmaster's Headache
- diff命令用法
- shell脚本之awk的简单使用
- 数组,字符串,cin cin.getline() cin.get() getline() gets()
- 图的关键路径
- 数据结构:线段树
- Headmaster's Headache UVA10817
- 空类与空结构体大小
- C/C++ 文件操作
- 程序算法与人生选择
- 非开发人员获取ios crashlog方法
- MTK预置可卸载的应用
- JavaSE第五十八讲:可变参数详解
- linux minicom 是linux 下串口调试工具
- 程序员应该读的故事:三个事和三个问题