2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh!
This problem will be judged on HDU. Original ID: 5383
64-bit integer IO format: %I64d Java class name: Main
Stilwell has n monsters on the desk, each monster has its leveli and ATKi. There are two kinds of monsters, Tuner monsters and Non-Tuner monsters.
Now, Stilwell plans to finish some "Synchro Summon", and "Synchro Summon" is a kind of special summon following these rules (a little different from the standard YGO rules):
(1) A "Synchro Summon" needs two monsters as the material of this summon, and they must be one Tuner monster and one Non-Tuner monster.
In other words, we can cost one Tuner monster and one Non-Tuner monster to get a Synchro monster ("cost" means remove form the desk, "get" means put on to the desk).
(2) To simplify this problem, Synchro monsters are neither Tuner monsters nor Non-Tuner monsters.
(3) The level sum of two material must be equal to the level of Synchro monster we summon.
For example:
A Level 3 Tuner monster + A Level 2 Non-Tuner monster = A Level 5 Synchro Monster
A Level 2 Tuner monster + A Level 4 Non-Tuner monster = A Level 6 Synchro Monster
A Level 4 Tuner monster + A Level 4 Non-Tuner monster = A Level 8 Synchro Monster
(4) The material of some Synchro monster has some limits, the material must contain some specific monster.
For example:
A Level 5 Synchro Monster α requires A Level 3 Tuner monster α to be its material
A Level 6 Synchro Monster β requires A Level 4 Non-Tuner monster β to be its material
A Level 8 Synchro Monster γ requires A Level 4 Tuner monster γ + A Level 4 Non-Tuner monster γ to be its material
A Level 5 Synchro Monster φ doesn't require any monsters to be its material
Then
A Level 3 Tuner monster α + A Level 2 Non-Tuner monster = A Level 5 Synchro Monster α
A Level 3 Tuner monster δ + A Level 2 Non-Tuner monster ≠ A Level 5 Synchro Monster α
A Level 2 Tuner monster + A Level 4 Non-Tuner monster β = A Level 6 Synchro Monster β
A Level 3 Tuner monster + A Level 3 Non-Tuner monster ζ ≠ A Level 6 Synchro Monster β
A Level 4 Tuner monster γ + A Level 4 Non-Tuner monster γ = A Level 8 Synchro Monster γ
A Level 4 Tuner monster σ + A Level 4 Non-Tuner monster γ ≠ A Level 8 Synchro Monster γ
A Level 4 Tuner monster γ + A Level 4 Non-Tuner monster ϕ ≠ A Level 8 Synchro Monster γ
A Level 3 Tuner monster + A Level 2 Non-Tuner monster = A Level 5 Synchro Monster φ
A Level 3 Tuner monster α + A Level 2 Non-Tuner monster = A Level 5 Synchro Monster φ
Stilwell has m kinds of Synchro Monster cards, the quantity of each Synchro Monster cards is infinity.
Now, given leveli and ATKi of every card on desk and every kind of Synchro Monster cards. Please finish some Synchro Summons (maybe zero) to maximum ∑ATKi of the cards on desk.
Input
For each test case, the first line contains two integers n, m.
Next n lines, each line contains three integers tuneri, leveli, and ATKi, describe a monster on the desk. If this monster is a Tuner monster, then tuneri=1, else tuneri=0for Non-Tuner monster.
Next m lines, each line contains integers levelj, ATKj, rj, and following rj integers are the required material of this Synchro Monster (the integers given are the identifier of the required material).
The input data guarantees that the required material list is available, two Tuner monsters or two Non-Tuner monsters won't be required. If ri=2 the level sum of two required material will be equal to the level of Synchro Monster.
T≤10, n,m≤300, 1≤leveli≤12, 0≤ATKi≤5000, 0≤ri≤2
Output
Sample Input
5
2 2
1 3 1300
0 2 900
5 2300 1 1
8 2500 0
2 1
1 3 1300
1 2 900
5 2300 1 1
3 1
1 3 1300
0 2 900
0 2 800
5 2300 1 1
3 1
1 1 233
0 1 233
0 1 200
2 466 2 1 2
6 3
1 3 1300
0 2 900
0 5 1350
1 4 1800
0 10 4000
0 10 1237
5 2300 1 1
8 3000 0
6 2800 0
Sample Output
2300
2200
3200
666
11037
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int INF = 0x3f3f3f3f;
class FUCK {
public:
struct arc {
int to,flow,cost,next;
arc(int x = ,int y = ,int z = ,int nxt = -) {
to = x;
flow = y;
cost = z;
next = nxt;
}
} e[maxn*maxn];
int head[maxn],d[maxn],p[maxn],tot,S,T;
bool in[maxn];
void init() {
memset(head,-,sizeof head);
tot = ;
}
void add(int u,int v,int flow,int cost) {
e[tot] = arc(v,flow,cost,head[u]);
head[u] = tot++;
e[tot] = arc(u,,-cost,head[v]);
head[v] = tot++;
}
bool spfa() {
queue<int>q;
q.push(S);
memset(d,0x3f,sizeof d);
memset(in,false,sizeof in);
memset(p,-,sizeof p);
d[S] = ;
while(!q.empty()) {
int u = q.front();
q.pop();
in[u] = false;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow && d[e[i].to] > d[u] + e[i].cost) {
d[e[i].to] = d[u] + e[i].cost;
p[e[i].to] = i;
if(!in[e[i].to]) {
in[e[i].to] = true;
q.push(e[i].to);
}
}
}
}
if(d[T] >= ) return false;
return p[T] > -;
}
int solve(int ret = ) {
while(spfa()) {
int minF = INF;
for(int i = p[T]; ~i; i = p[e[i^].to])
minF = min(minF,e[i].flow);
for(int i = p[T]; ~i; i = p[e[i^].to]) {
e[i].flow -= minF;
e[i^].flow += minF;
}
ret += minF*d[T];
}
return ret;
}
};
class YGO {
public:
int tunner[maxn],atk[maxn],lev[maxn],w[maxn][maxn],ret;
int n,m;
FUCK cao;
void update(int a,int b,int val) {
if(tunner[a] < tunner[b]) w[a][b] = max(w[a][b],val);
if(tunner[b] < tunner[a]) w[b][a] = max(w[b][a],val);
}
void init() {
memset(w,,sizeof w);
scanf("%d%d",&n,&m);
cao.init();
ret = cao.S = ;
cao.T = n + ;
for(int i = ; i <= n; ++i) {
scanf("%d%d%d",tunner+i,lev+i,atk+i);
ret += atk[i];
if(tunner[i]) cao.add(i,cao.T,,);
else cao.add(cao.S,i,,);
}
for(int i = ; i <= m; ++i) {
int lv,ak,nm,a,b;
scanf("%d%d%d",&lv,&ak,&nm);
if(nm == ) {
for(int j = ; j <= n; ++j) {
for(int k = j+; k <= n; ++k)
if(lev[j] + lev[k] == lv)
update(j,k,ak - atk[j] - atk[k]);
}
}
if(nm == ) {
scanf("%d",&a);
for(int j = ; j <= n; ++j) {
if(lev[a] + lev[j] == lv)
update(a,j,ak - atk[a] - atk[j]);
}
}
if(nm == ) {
scanf("%d%d",&a,&b);
update(a,b,ak - atk[a] - atk[b]);
}
}
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
if(w[i][j]) cao.add(i,j,,-w[i][j]);
printf("%d\n",ret - cao.solve());
} } BB;
int main() {
int kase;
scanf("%d",&kase);
while(kase--) BB.init();
return ;
}
2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 7 hdu 5378 Leader in Tree Land
Leader in Tree Land Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- 分享一个iOS输入框特殊限制的代码 UITextField (Validation)
//个人总结.欢迎新增或改动 #import <UIKit/UIKit.h> typedef enum{ VALIDATION_TYPE_NUM_VALIDATED = 0,//数字 VA ...
- zoj3886--Nico Number(素数筛+线段树)
Nico Number Time Limit: 2 Seconds Memory Limit: 262144 KB Kousaka Honoka and Minami Kotori are ...
- hdoj--1150--Machine Schedule(最小点覆盖)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- php navigat备份
点击查询->新建查询->写sql查询出更新的数据部分(根据时间等条件) -> 点击上方工具菜单栏的导出向导 ,然后就可以根据选择导出文件了可以导出sql脚本excel等很多,绝对有你 ...
- Gym-101915A Printing Books 模拟
题面 题意:给你N,X, X表示这本书从X开始编号,每个X是几位数,计数器就加几, 然后问你如果从X,开始编号,计数器为N的时候,翻了几页,不能刚好为N输出-1. (例如,5 99,答案为2,因为 ...
- Linux 定时任务 Crontab按秒执行
目前在crontab中最小执行时间单位为分钟. 如果需要按秒来执行,有以下两种方法: 方法一:通过sleep来实现 例: 1.创建test.php文件,这里测试通过打印时间好区分. <?php ...
- .net core发布到IIS后502.5错误
net core 在win7系统发布后,出现在502.5错误. 打开“开始”菜单,搜索“事件查看器”,然后选择“事件查看器”应用. 在“事件查看器”中,打开“Windows 日志”节点. 选择“应用程 ...
- Springboot使用AOP实现统一处理Web请求日志
1.要使我们自定义的记录日志能够打印出来,我们需要先排除springboot默认的记录日志,添加如下的设置 2.新建 resources/log4j.properties 我的设置为: # LOG4J ...
- Python中断言与异常的区别
异常,在程序运行时出现非正常情况时会被抛出,比如常见的名称错误.键错误等. 异常: >>> s Traceback (most recent call last): File &qu ...
- Gitlab 灾备措施
Gitlab创建备份 使用Gitlab一键安装包安装Gitlab非常简单,同样的备份恢复与迁移也非常简单.使用一条命令即可创建完整的Gitlab备份: gitlab-rake gitlab:ba ...