The city planners plan to build N plants in the city which has M shops.

Each shop needs products from some plants to make profit of proiproi units.

Building ith plant needs investment of payipayi units and it takes titi days.

Two or more plants can be built simultaneously, so that the time for building multiple plants is maximum of their periods(titi).

You should make a plan to make profit of at least L units in the shortest period. 

InputFirst line contains T, a number of test cases.

For each test case, there are three integers N, M, L described above.

And there are N lines and each line contains two integers payipayi, titi(1<= i <= N).

Last there are M lines and for each line, first integer is proiproi, and there is an integer k and next k integers are index of plants which can produce material to make profit for the shop.

1 <= T <= 30 
1 <= N, M <= 200 
1≤L,ti≤10000000001≤L,ti≤1000000000 
1≤payi,proi≤300001≤payi,proi≤30000 
OutputFor each test case, first line contains a line “Case #x: t p”, x is the number of the case, t is the shortest period and p is maximum profit in t hours. You should minimize t first and then maximize p.

If this plan is impossible, you should print “Case #x: impossible” 
Sample Input

2

1 1 2
1 5
3 1 1 1 1 3
1 5
3 1 1

Sample Output

Case #1: 5 2
Case #2: impossible
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 405
#define L 31
#define INF 1000000009
#define eps 0.00000001
#define sf(a) scanf("%lld",&a)
struct plant
{
LL pay, time;
LL id;
bool operator<(const plant& rhs) const
{
return time < rhs.time;
}
};
struct shop
{
LL cnt, time, pro;
LL pl[MAXN];
};
shop s[MAXN];
plant p[MAXN];
LL g[MAXN << ][MAXN << ];
LL level[MAXN<<];
LL T, n, m, l, st, ed, ans, tmp;
bool bfs()
{
memset(level, -, sizeof(level));
level[st] = ;
queue<LL> q;
q.push(st);
while (!q.empty())
{
LL f = q.front();
q.pop();
for (LL i = ; i <= ed; i++)
{
if (level[i] == - && g[f][i] > )
{
level[i] = level[f] + ;
q.push(i);
}
}
}
return level[ed] > ;
}
LL dinic(LL k, LL low)
{
if (k == ed)return low;
LL a;
for (LL i = ; i <= ed; i++)
{
if (level[i] == level[k] + && g[k][i] > && (a = dinic(i, min(low, g[k][i]))))
{
g[k][i] -= a;
g[i][k] += a;
return a;
}
}
return ;
}
void solve()
{
ans = ;
while (bfs())
{
while (tmp = dinic(st, INF))
ans += tmp;
}
}
int main()
{
sf(T);
for (LL cas = ; cas <= T; cas++)
{
sf(n), sf(m), sf(l);
for (LL i = ; i <= n; i++)
{
sf(p[i].pay), sf(p[i].time);
p[i].id = i;
}
for (LL i = ; i <= m; i++)
{
sf(s[i].pro);
sf(s[i].cnt);
s[i].time = ;
for (LL j = ; j < s[i].cnt; j++)
{
sf(s[i].pl[j]);
s[i].time = max(s[i].time, p[s[i].pl[j]].time);
}
}
sort(p + , p + + n);
bool f = false;
st = n + m + , ed = st + ;
printf("Case #%lld: ", cas);
for (LL i = ; i <= n; i++)
{
memset(g, , sizeof(g));
for (LL j = ; j <= i; j++)
g[p[j].id][ed] = p[j].pay;
LL tot = ;
for (LL j = ; j <= m; j++)
{
if (s[j].time <= p[i].time)
{
tot += s[j].pro;
g[st][j + n] = s[j].pro;
for (LL k = ; k < s[j].cnt; k++)
g[j + n][s[j].pl[k]] = INF;
}
}
solve();
ans = tot - ans;
if (ans >= l)
{
printf("%lld %lld\n", p[i].time, ans);
f = true;
break;
}
}
if (!f)
printf("impossible\n");
}
}

Less Time, More profit 最大权闭合子图(最大流最小割)的更多相关文章

  1. HDU 5855 Less Time, More profit 最大权闭合子图

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5855 Less Time, More profit Time Limit: 2000/1000 MS ...

  2. 【最大权闭合子图 最小割】bzoj1497: [NOI2006]最大获利

    最大权闭合子图的模型:今天才发现dinic板子是一直挂的…… Description 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在 ...

  3. 洛谷 P4174 [NOI2006]最大获利 && 洛谷 P2762 太空飞行计划问题 (最大权闭合子图 && 最小割输出任意一组方案)

    https://www.luogu.org/problemnew/show/P4174 最大权闭合子图的模板 每个通讯站建一个点,点权为-Pi:每个用户建一个点,点权为Ci,分别向Ai和Bi对应的点连 ...

  4. bzoj 1497 [NOI2006]最大获利【最大权闭合子图+最小割】

    不要被5s时限和50000点数吓倒!大胆网络流!我一个5w级别的dinic只跑了1s+! 看起来没有最大权闭合子图的特征--限制,实际上还是有的. 我们需要把中转站看成负权点,把p看成点权,把客户看成 ...

  5. 洛谷 P2762 太空飞行计划问题 【最大权闭合子图+最小割】

    --一道难在读入的题. 最后解决方案直接getline一行然后是把读优拆掉放进函数,虽然很丑但是过了. 然后就是裸的最大权闭合子图了,把仪器当成负权点向t连流量为其价格的边,s向实验连流量为实验报酬的 ...

  6. BZOJ 1565 / P2805 [NOI2009]植物大战僵尸 (最大权闭合子图 最小割)

    题意 自己看吧 BZOJ传送门 分析 - 这道题其实就是一些点,存在一些二元限制条件,即如果要选uuu则必须选vvv.求得到的权值最大是多少. 建一个图,如果选uuu必须选vvv,则uuu向vvv连边 ...

  7. 【最大权闭合子图/最小割】BZOJ3438-小M的作物【待填】

    [题目大意] 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物的种子,每种作物的种子有1个(就是可以种一棵作物)(用1...n编号),现在,第i种作物种植在A中种植 ...

  8. HDU5855 Less Time, More profit(最大权闭合子图)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...

  9. 2018.11.06 NOIP训练 最大获利(profit)(01分数规划+最大权闭合子图)

    传送门 好题啊. ∑i<jpi,jK∗(200−K)>X\frac{\sum_{i<j}p_{i,j}}{K*(200-K)}>XK∗(200−K)∑i<j​pi,j​​ ...

随机推荐

  1. JDK常用类解读--String

    一.字符串的不变性: 文章使用的源码是jdk1.8的.(下同) 1.首先可以看到`String`是`final`类,说明该类不可继承,保证不会被子类改变语义 2.String的值实际上就是一个字符数组 ...

  2. VMware Workstation安装CentOS 7和开发环境

    VMware Workstation新建虚拟机 此处使用的是VMware Workstation 10,其安装过程即是常规Windos系统下软件安装方式,略过. 安装完成双击图标: 打开虚拟机主界面: ...

  3. linux下安装mysql5.7.21

    下载 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 解压 ...

  4. schtasks /create 计划任务 中文路径 名字都要加“” 子命令 /tn /tr 前面要空格 否则会出错

    echo off echo. 清空连接 net use * /del /y echo. 连接 net use \\192.168.1.2\人力资源部\考勤\考勤数据-小莫提供 "密码&quo ...

  5. 软件开发:速度 vs 质量

    程序开发项目进行过程中,通常会冒出这样的困惑:应该选择速度,还是选择质量?很多程序猿都会有偷懒的思维,觉得把一些摸不清头绪.不知道怎么写的代码片段去掉,可以节省很多时间,更早完成项目计划. 其实过去几 ...

  6. MySQL系列(一)--数据类型

    如何选择优化的数据类型: 1.通常更小的更好 相同级别的数据类型,选择占据空间更小的数据类型.更小的数据类型通常更快,因为占用更少的磁盘.内存和CPU缓存,处理时需要的 CPU周期也更少,但是要确保需 ...

  7. NPOI--------------.Net操作Excel初步使用(导出)

    背景 因公司项目需要添加数据导出功能故此添加,找了几种方式发现该方式具有 无需依赖本机安装office环境,使用灵活等优点故采用此方式. 安装 Nuget 直接安装NPOI即可 使用方式 1.根据需要 ...

  8. 梯度提升决策树(GBDT)与XGBoost、LightGBM

    今天是周末,之前给自己定了一个小目标:每周都要写一篇博客,不管是关于什么内容的都行,关键在于总结和思考,今天我选的主题是梯度提升树的一些方法,主要从这些方法的原理以及实现过程入手讲解这个问题. 本文按 ...

  9. 获取本地验证码cookie

    window.document.onkeydown = function (evt) { evt = (evt) ? evt : window.event; if (evt.keyCode) { if ...

  10. 小甲鱼python疑难点

    1.python生成器 2.while 1: num = input('请输入一个整数(输入Q结束程序):') if num != 'Q': num = int(num) print('十进制 -&g ...