HDU 3720
来源:互联网 发布:局域网现场直播软件 编辑:程序博客网 时间:2024/06/02 03:06
没什么好说的,最近太水,各种犯2...
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <string>#include <vector>#include <map>#include <set>#include <queue>#include <algorithm>#include <iostream>#include <sstream>using namespace std;const int inf = 1000000000;struct Player { string name; int ability; string position; bool operator < (const Player &oth) const { return position < oth.position; }} player[23];int additional[23][23];int find(const string &name) { for (int i = 0; ; i++) if (player[i].name == name) return i;}int pd, pg, pm, ps; // 分别是第一个后卫、第一个守门员、第一个中场、第一个前锋在player中的位置。vector<int> select;int ans;void dfs(int x) { if (select.size() >= 11) { int tmp = 0; for (int i = 0; i < 11; i++) { tmp += player[select[i]].ability; for (int j = i + 1; j < 11; j++) tmp += additional[select[i]][select[j]]; } if (tmp > ans) ans = tmp; return; } if (x >= 23) return; int y = x + 1; if (select.size() >= 9) { if (23 - y >= 11 - select.size()) dfs(y); // 如果可以不选x select.push_back(x); if (select.size() == 11) y = 23; // 如果选了x,已经有11人被选 dfs(y); select.pop_back(); } else if (select.size() >= 5) { if (ps - y >= 9 - select.size()) dfs(y); // 如果可以不选x select.push_back(x); if (select.size() == 9) y = ps; // 如果选了x,已经有9人被选(不需要中场了) dfs(y); select.pop_back(); } else if (select.size() >= 4) { if (pm - y >= 5 - select.size()) dfs(y); // 如果可以不选x select.push_back(x); if (select.size() == 5) y = pm; // 如果选了x,已经有5人被选(不需要守门员了) dfs(y); select.pop_back(); } else { if (pg - y >= 4 - select.size()) dfs(y); // 如果可以不选x select.push_back(x); if (select.size() == 4) y = pg; // 如果选了x,已经有4人被选(不需要后卫了) dfs(y); select.pop_back(); }}int main() { int i, m, a, b, profit; string namea, nameb; while (cin >> player[0].name >> player[0].ability >> player[0].position) { for (i = 1; i < 23; i++) cin >> player[i].name >> player[i].ability >> player[i].position; sort(player, player + 23); cin >> m; memset(additional, 0, sizeof(additional)); for (i = 0; i < m; i++) { cin >> namea >> nameb >> profit; a = find(namea); b = find(nameb); additional[a][b] = additional[b][a] = profit; } pd = pg = pm = ps = -1; for (i = 0; i < 23; i++) { switch (player[i].position[0]) { case 'd': if (pd == -1) pd = i; break; case 'g': if (pg == -1) pg = i; break; case 'm': if (pm == -1) pm = i; break; case 's': if (ps == -1) ps = i; break; } } if (pd == -1 || pg == -1 || pm == -1 || ps == -1 || pg - pd < 4 || pm - pg < 1 || ps - pm < 4 || 23 - ps < 2) { cout << "impossible" << endl; continue; } ans = -inf; dfs(0); cout << ans << endl; } return 0;}
- HDU 3720
- HDU 3720
- HDU 3720 DFS
- hdu 3720 暴力枚举
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- C#使用进度条,并用线程模拟真实数据 ProgressBar用法
- perl http get和post
- jquery第一个子节点怎么获得
- lr压力测试的迭代次数
- 快捷渐变效果
- HDU 3720
- 聚合函数&groupby&having
- 关于CGI的那点事
- 利用 squid 反向代理提高网站性能
- 每个IT人都应当拥有的30条技能
- POSIX线程清理函数
- 如何使用android SDK开发android 应用
- 操作寄存器错误Unable to handle kernel NULL pointer dereference at virtual address的解决办法
- getchar的返回值问题