Yu-Gi-Oh!

Time Limit: 2000ms
Memory Limit: 65536KB

This problem will be judged on HDU. Original ID: 5383
64-bit integer IO format: %I64d      Java class name: Main

 
"Yu-Gi-Oh!", also known as "Dueling Monsters", is a popular trading card game which has nearly 20 years history. Next year, YGO will reach its 20th birthday.

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

The first line of the input contains a single number T, the number of test cases.

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

T lines, find the maximum ∑ATKi after some Synchro Summons.

 

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

 
解题:费用流。。。Orz
 
哎 ,还是写类比较好,可以把相同变量隔离开来
 
 #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!的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. STM32的IO配置点灯

    1.led.c的详细的代码: /*----------------------------------------------------------*/ #include "led.h&q ...

  2. C++设计模式之状态模式(二)

    2.智能空调的设计与实现 某软件公司将开发一套智能空调系统: 系统检測到温度处于20---30度之间,则切换到常温状态:温度处于30---45度,则切换到制冷状态: 温度小于20度,则切换到制热状态. ...

  3. 《从零開始学Swift》学习笔记(Day48)——类型检查与转换

    原创文章,欢迎转载.转载请注明:关东升的博客 继承会发生在子类和父类之间,是一系列类的继承关系. 比如:Person是类层次结构中的根类.Student是Person的直接子类.Worker是Pers ...

  4. DNS负载均衡 Nginx 负载均衡的种类

    DNS负载均衡 当一个网站有足够多的用户的时候,假如每次请求的资源都位于同一台机器上面,那么这台机器随时可能会蹦掉.处理办法就是用DNS负载均衡技术,它的原理是在DNS服务器中为同一个主机名配置多个I ...

  5. 逻辑运算0==x和x==0具体解释

    看很多大牛写的程序经常看到if(0==x){运行体},而自己写的程序常用if(x==0){运行体}.刚開始的时候我还非常自信的觉得这样的表达方式是等价的,大牛们仅仅是为了显摆下与众不同的格调.当读到C ...

  6. Linux - 配置php-fpm 以及 配置nginx支持php

    配置php-fpm [root@localhost php7]# which php-fpm /usr/local/php7/sbin/php-fpm [root@localhost php7]# p ...

  7. 【Codeforces 105D】 Bag of mice

    [题目链接] http://codeforces.com/contest/148/problem/D [算法] 概率DP f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 : 1. ...

  8. DBS-PowerDesginer:PowerDesigner最基础的使用方法入门学习

    ylbtech-DBS-PowerDesginer:PowerDesigner最基础的使用方法入门学习 1.返回顶部 1. 1:入门级使用PowerDesigner软件创建数据库(直接上图怎么创建,其 ...

  9. 表格td内容过多时,td显示省略号,鼠标移入显示全部内容。

    转自:https://blog.csdn.net/weixin_42193908/article/details/80405014 两种方式显示: 1.title方式显示: <!DOCTYPE ...

  10. 最详细的CentOS 6与7对比(二):服务管理对比

    本主题将从3个角度进行对比 常见设置(CentOS 6 vs CentOS 7) 服务管理(Sysvinit vs Upstart vs Systemd) 性能测试(cpu/mem/io/oltp) ...