uva 1508 Equipment(暴力+枚举子集)
来源:互联网 发布:淘宝账号无限注册 编辑:程序博客网 时间:2024/06/05 14:24
uva 1508 Equipment
题目大意:给出n个5元组,要求从中选取k个,要求5个位置上的数的最大值的和尽量大。
#include<stdio.h>#include<string.h>#include<algorithm>#include<stdlib.h>using namespace std;int num[10005][6], temp[40], ans, n, k;void DFS(int pos, int sum, int d) {if (d == k) {ans = max(sum, ans);return;}for (int i = pos; i; i = (i - 1) & pos) {DFS(pos^i , sum + temp[i], d + 1);}return;}int main() {int T;scanf("%d\n", &T);while (T--) {memset(num, 0, sizeof(num));memset(temp, 0, sizeof(temp));scanf("%d %d\n", &n, &k);for (int i = 0; i < n; i++) {for (int j = 0; j < 5; j++) {scanf("%d", &num[i][j]);temp[j] = max(temp[j], num[i][j]);}}if (k >= 5) {printf("%d\n", temp[0] + temp[1] + temp[2] + temp[3] + temp[4]);continue;}memset(temp, 0, sizeof(temp));for (int i = 0; i < n; i++) {for (int pos = 0; pos < 32; pos++) { //5位32种情况int sum = 0;for (int j = 0; j < 5; j++) {if (pos & (1<<j)) { sum += num[i][j];}}temp[pos] = max(temp[pos], sum); //32种情况,每种情况的最大值}}ans = 0;DFS(31, 0, 0);printf("%d\n", ans);}return 0;}
0 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 暴力枚举
- MyBatis排序时使用order by 动态参数时需要注意,用$而不是#
- 微信里如何判断页面被分享成功
- centos 安装nginx + 多个tomcat负载均衡
- 数学建模总结(二)
- Edittext 多行显示和光标指向第一行
- uva 1508 Equipment(暴力+枚举子集)
- C#+arcengine调用GP工具实现extract values to points的功能(可以用来高程)
- ubuntu双网卡双IP设置并实现同时访问外网的功能
- Dev GirdView 去掉系统菜单增加自定义菜单
- Grails 2.4.4+idea 14 创建debug模式
- Android之TabHost布局
- Windows server 2012远程桌面会话主机和远程桌面授权
- ORA-01090 shutdown in progress - connection is not permitted
- 检测Xpath版本