[dp]1396:Select Team
来源:互联网 发布:java poi api下载 编辑:程序博客网 时间:2024/05/22 14:25
Description
The first line has a integer T (T <=10) represents the number of cases. For each test cases, the first line has two numbers K, N (1 <= K <= 6, 3*K<=N<=18) which show the number of teams and the number of candidates. The second line has N integers A1.. An ,(0<=Ai<=100000) which represents the personal talent or personal skills for each candidates. The following N lines, every line has N integers which is a matrix Wnn. Wij describe the teamwork skill between team member i and j, 0<=Wij<=100000,and Wij=Wji.
Output
For every case, output a integer which is maximum score for K teams.
Sample Input
11 410 10 10 110 15 5 015 0 15 155 15 0 50 15 5 0Sample Output
66
题目大意:
A[a]+A[b]+A[c]+W[a][b]+W[a][c]+W[b][c] 为a,b,c三人组成队伍的实力。
按照最佳策略组队,求这k个队伍的最大实力总和
#include<iostream>#include<cstring>#include <bitset>#include<cstdio>using namespace std;const int MAXN = (1 << 18);int w[MAXN], f[MAXN], bcnt[MAXN], g_k, g_n;void reader(){ int i, j, t, a[20]; scanf("%d%d", &g_k, &g_n); for (i = 0; i < g_n; i++) scanf("%d", a + i); for (i = 0; i < g_n; i++) { for (j = 0; j < g_n; j++) { scanf("%d", &t); w[(1 << i) | (1 << j)] = 2 * t + a[i] + a[j]; } }}int work(){ int i, s, res = 0; bool at[20] = {0}; memset(f, 0, sizeof (f)); for (i = 0; i <= g_k; i++) at[3 * i] = true; for (s = 1; s < (1 << g_n); s++) { if (at[bcnt[s]]) { int b0 = s&-s; int s1 = s^b0; while (s1) { int b1 = s1&-s1; s1 ^= b1; int s2 = s1; while (s2) { int b2 = s2&-s2; s2 ^= b2; int t = w[b0 | b1] + w[b0 | b2] + w[b1 | b2] + f[s^b0^b1^b2]; if (f[s] < t)f[s] = t; } } if (res < f[s])res = f[s]; } } return res;}int main(){ int s, t; bcnt[0] = 0; for (s = 1; s < MAXN; s++) bcnt[s] = bcnt[s >> 1]+(s & 1); scanf("%d", &t); while (t--) { reader(); int res = work(); printf("%d\n", res / 2); } return 0;}
说实话,很难理解。。。
- [dp]1396:Select Team
- USCoj 1396- Select Team 状压DP
- bzoj1722 [Usaco2006 Mar] Milk Team Select 产奶比赛(树形dp)
- 图论+dp poj 1112 Team Them Up!
- POJ 1112 Team Them Up! DP
- ZOJ 3872 - Team Formation(DP)
- Team
- Team
- 【iOS】Signing for requires a development team. Select a development team in the project editor. Code
- Signing for requires a development team. Select a development team in the project editor. Code
- Signing for "xxx" requires a development team. Select a development team
- ios Signing for "" requires a development team. Select a development team in the project editor.
- Signing for requires a development team. Select a development team in the project editor. Code
- USACO MAR 2006 Milk Team Select(产奶比赛)
- 1722: [Usaco2006 Mar] Milk Team Select 产奶比赛
- POJ1112 Team Them Up! 连通图 染色 DP
- poj 1112 Team Them Up!(建图+dp)
- ZOJ 1462 Team Them Up! (二分图+路径保存DP)
- @ModelAttribute注解的用法
- read_text/sav_text
- UIScrollView
- 初学node.js之控制台输出and监听http请求
- 字符串逆序输出(nyoj266)
- [dp]1396:Select Team
- Xcode6添加pch文件
- Entity Framework 全面教程详解(转)
- 5555555555555555555555555
- Unity3D Compute Shader 晋级 网格模拟与奶茶泡泡【四】
- 第十一周阅读程序(1)
- java动画
- IOS 开发学习 十四 与CGRect相关的几个结构体和画图有关的几个函数
- ABAP利用HTTP调用要用户验证的web service