FZU 1980 AbOr's story
AbOr's story
This problem will be judged on FZU. Original ID: 1980
64-bit integer IO format: %I64d Java class name: Main
As we all known, AbOr has a lots of girls in a palace called “Hou” (About 30 millions).
The girls in the palace love gemstones, such as cat’s eye, garnet, amethyst and so on. If AbOr wants to play with one girl, he must take all the gemstones the girl wants. But the girl would not take any gemstones away. Though the gemstone is expensive, but AbOr is a businessman and he has infinity money. If AbOr plays with one girl, he will feel happy and she will help AbOr to make some money. AbOr likes the new and loathes the old, so if he plays with one girl he used to play with, he will not feel happy any more, of course make no money. Initially AbOr has no gemstones.
The evil AbOr want to make as much money as possible. But he is very busy, so your task is to help him to calculate the maximum money he can make.
Input
Output
For each test case, print a line containing the test case number (beginning with 1) and the maximum money AbOr can make.
Sample Input
3 1 2 2 1 2 100 3 7 1 2 1 1 100 1000 10000 2 1 1 1 100 1 1 16 17
Sample Output
Case 1: 90 Case 2: 0 Case 3: 99
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 50010; 18 struct arc{ 19 int to,next; 20 LL flow; 21 arc(int x = 0,LL y = 0,int z = -1){ 22 to = x; 23 flow = y; 24 next = z; 25 } 26 }; 27 arc e[600000]; 28 int head[maxn],d[maxn],cur[maxn]; 29 int tot,S,T,n,m; 30 void add(int u,int v,LL flow){ 31 e[tot] = arc(v,flow,head[u]); 32 head[u] = tot++; 33 e[tot] = arc(u,0,head[v]); 34 head[v] = tot++; 35 } 36 bool bfs(){ 37 memset(d,-1,sizeof(d)); 38 d[S] = 1; 39 queue<int>q; 40 q.push(S); 41 while(!q.empty()){ 42 int u = q.front(); 43 q.pop(); 44 for(int i = head[u]; ~i; i = e[i].next){ 45 if(e[i].flow && d[e[i].to] == -1){ 46 d[e[i].to] = d[u] + 1; 47 q.push(e[i].to); 48 } 49 } 50 } 51 return d[T] > -1; 52 } 53 LL dfs(int u,LL low){ 54 if(u == T) return low; 55 LL tmp = 0,a; 56 for(int &i = cur[u]; ~i; i = e[i].next){ 57 if(e[i].flow && d[e[i].to] == d[u] + 1 &&(a=dfs(e[i].to,min(e[i].flow,low)))){ 58 e[i].flow -= a; 59 e[i^1].flow += a; 60 tmp += a; 61 low -= a; 62 if(!low) break; 63 } 64 } 65 if(!tmp) d[u] = -1; 66 return tmp; 67 } 68 LL dinic(){ 69 LL ans = 0; 70 while(bfs()){ 71 memcpy(cur,head,sizeof(head)); 72 ans += dfs(S,INF); 73 } 74 return ans; 75 } 76 int main() { 77 int csn = 1,cs,ks,u,v,w; 78 scanf("%d",&cs); 79 while(cs--){ 80 scanf("%d %d",&n,&m); 81 memset(head,-1,sizeof(head)); 82 S = tot = 0; 83 T = n+m+1; 84 LL ans = 0; 85 for(int i = 1; i <= n; ++i){ 86 scanf("%d",&ks); 87 while(ks--){ 88 scanf("%d",&u); 89 add(i,u+n,INF); 90 } 91 scanf("%d",&w); 92 add(S,i,w); 93 ans += w; 94 } 95 for(int i = 1; i <= m; ++i){ 96 scanf("%d",&w); 97 add(i+n,T,w); 98 } 99 printf("Case %d: %I64d\n",csn++,ans - dinic()); 100 } 101 return 0; 102 }
View Code
转载于:https://www.cnblogs.com/crackpotisback/p/4054050.html
FZU 1980 AbOr's story相关推荐
- fzu 2150 Fire Game 【身手BFS】
称号:fzu 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个格子扩散,问选择那两个点使得燃烧全部 ...
- 用Python分析了1980~2015年考研英语真题词汇,原来考研英语应该这样考!
微信改版,加星标不迷路! 用Python分析了1980~2015年考研英语真题词汇,原来考研应该这样考! 作者:阿广 概述 前言 数据介绍 实现过程 考研英语词汇统计分析 搞笑一刻 阿广说 每日问题 ...
- FZU 1686 神龙的难题(DLX反复覆盖)
FZU 1686 神龙的难题 题目链接 题意:中文题 思路:每个1看成列,每个位置作为左上角的矩阵看成行.dlx反复覆盖就可以 代码: #include <cstdio> #include ...
- FZU 1649 Prime number or not (Miller-Rabin素数测试)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1649 题目大意:很直接,判断一个数n(2<=n<=10^18)是不是素数. 当n达到long ...
- FZU 2159 WuYou
FZU 2159 题意:给你两个串,A串和B串,其中A串有些不确定.叫你求 A < B的最大A串 做法:一开始做错了.去问小坤子,他讲了一下他的思路.就是开一个 f 数组.f[i]表示从第i位开 ...
- FZU 1019猫捉老鼠
A - 猫捉老鼠 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- FZU 2214 Knapsack problem(背包问题)
Description 题目描述 Given a set of n items, each with a weight w[i] and a value v[i], determine a way t ...
- 机器人学习--Hans Moravec在斯坦福博士论文1980年-Obstacle Avoidance and Navigation in the Real World by a Seeing Ro
Hans Moravec,占用栅格地图的发明人. Obstacle Avoidance and Navigation in the Real World by a Seeing Robot Rover ...
- FZU Monthly-201903 获奖名单
FZU Monthly-201903 获奖名单 冠军: 黄海东 S031702647 一等奖: 林闽沪 S131700309 陈华能 S221701416 二等奖: 鲍子涵 S031702646 吴少 ...
最新文章
- android学生个人事物管理系统,基于Android平台的学生个人事务管理系统的设计与实现(整理版).doc...
- 斯坦福:「目标检测」深度学习全面指南
- TF:利用TF读取数据操作,将CIFAR-10 数据集中的训练图片读取出来,并保存为.jpg格式
- VTK修炼之道46:图形基本操作进阶_三角网格体积、表面积、测地距离、包围盒
- 使用 LxRunOffine 迁移 WSL Ubuntu安装目录
- Boost:双图bimap与Boost xpressive的测试程序
- RocketMQ安装内存不足的问题
- 函数式编程(一) 认识“编程范式”和“函数”
- python中os模块作用
- Python爬虫实例项目大全
- 关于黑苹果耳机麦克风无法正常输入输出以及VoodooHDA启动慢 解决方法
- 五分钟带你玩转rabbitmq(八)【真实案例】消息消费失败如何处理?
- 非线性动力学_非线性随机动力学团队2019大事件回顾
- U盘启动CDLinux制作方法
- lpx寒假作业案例4
- 傅立叶级数与傅里叶变换
- 廊坊金彩教育:店铺详情页设计要点
- Excel 常用技巧目录
- 娃哈哈的困境,宗庆后的难题
- Yolov5身份证检测——模型训练