uva 1508 - Equipment(暴力+枚举子集)
来源:互联网 发布:淘宝里面我的店铺在哪 编辑:程序博客网 时间:2024/06/05 14:27
题目链接:uva 1508 - Equipment
题目大意:给出n个5元组,要求从中选取k个,要求5个位置上的数的最大值的和尽量大。
解题思路:对于每个元组,有25−1种选取方法,那么处理出这些选取方法中的最大值即可,然后暴力枚举。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 10005;const int maxm = 5;const int maxs = (1<<5)-1;const int INF = 0x3f3f3f3f;int N, K;int num[maxn][maxm+5], rec[maxs+5];void cal (int a[maxm+5]) { for (int s = 0; s <= maxs; s++) { int tmp = 0; for (int j = 0; j < maxm; j++) if (s&(1<<j)) tmp += a[j]; rec[s] = max(rec[s], tmp); }}void init () { scanf("%d%d", &N, &K); K = min(K, maxm); memset(rec, 0, sizeof(rec)); for (int i = 0; i < N; i++) { for (int j = 0; j < maxm; j++) scanf("%d", &num[i][j]); cal(num[i]); }}int dfs (int d, int S) { if (d == K) return S ? -INF : 0; if (S == 0) return -INF; int ans = 0; for (int s0 = S; s0; s0 = (s0-1)&S) ans = max(ans, dfs(d+1, s0^S) + rec[s0]); return ans;}int main () { int cas; scanf("%d", &cas); while (cas--) { init(); printf("%d\n", dfs(0, maxs)); } return 0;}
1 0
- uva 1508 - Equipment(暴力+枚举子集)
- uva 1508 Equipment(暴力+枚举子集)
- uva 1508 - Equipment(暴力+枚举子集)
- UVa 1508 - Equipment (状态压缩 + 枚举子集)
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
- UVa 1508 Equipment 解题报告(枚举子集)
- UVA 1508 Equipment(技巧枚举)
- UVA 1354 - Mobile Computing(暴力枚举子集)
- uva 11205 The broken pedometer(暴力枚举+子集生成)
- 【暴力】枚举子集
- UVA1508-Equipment(状态压缩+暴力枚举)
- uva 11205(枚举子集)
- uva 131(枚举子集)
- UVa:1508 Equipment
- UVA - 1508 Equipment DFS
- uva 565(暴力+枚举)
- Uva 1595 暴力枚举
- UVA 455 暴力枚举
- TestLink环境搭建
- 动态规划第4讲——计数问题中的DP算法
- 并查集
- ValueError: can't find recovery API version in input target-files
- 联想昭阳E4430G触摸板无法禁用
- uva 1508 - Equipment(暴力+枚举子集)
- java 多线程
- Mysql从客户端连接服务器连不上的问题
- 101 - The Blocks Problem
- Android 应用程序退出后不在运行列表中显示的方法
- MySQL 清空所有的bin-log日志
- IOS之同步请求、异步请求、GET请求、POST请求
- Linux下检测FTP服务并开启FTP服务
- css3--我们太阳系