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 ;
}

最新文章

  1. java函数
  2. ios7开发学习笔记-包括c oc 和ios介绍
  3. PHP 用QueryList抓取网页内容
  4. eclipse注释模板
  5. 筛1-n中每个数的因子(nlogn)
  6. 手机端的表单验证和PC端的不同
  7. sql基础,必须会的————随便整理、杂乱无章
  8. 在IIS中部署Asp.net Mvc
  9. 201521123075 《Java程序设计》第2周学习总结
  10. TCP协议的滑动窗口协议以及流量控制
  11. Pseudo-devices On GNU/Linux
  12. grpc的服务注册与发现及负载
  13. python+appium 查找某个元素find_element()并click()点击,正向判断与反判断的方法封装
  14. python中的zip()函数和map()函数
  15. python学习第30天
  16. Python 限制线程的最大数量(Semaphore)
  17. 解决linux用户切换失败 su:execute /usr/bin 没有权限
  18. Qt 使用openGL 渲染YUV420P格式的视频
  19. C# 修改编译版本的方法
  20. VSCode一直弹框错误Linter pylint is not installed

热门文章

  1. 随机获取一个集合(List, Set)中的元素,随机获取一个Map中的key或value
  2. 具体解释linux文件处理的的经常使用命令
  3. maven+springMVC+mybatis+easyUI管理用户增删改查
  4. Android软键盘状态的切换及其强制隐藏
  5. MEAN框架介绍
  6. Java基础:异常捕获顺序
  7. 用树莓派实现RGB LED的颜色控制——C语言版本号
  8. 在android中读写文件
  9. 向量叉乘 Cross product
  10. Python基本数据类型之字符串str