二分t+最大权闭合图。

很显然二分那个t作为limit。每一个limit下,有一些边不能用了,然后要知道这种情况下怎么选点获得的价值最大。

这么想:一个shop想获得收益,就必须选择某一些plant,问题就转化成了最大权闭合图。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} int T,n,m;
int L;
struct X
{
int pay;
int t;
}p[];
vector<int>g[];
int pro[];
bool flag[],se[]; const int maxn = + ;
const int INF = 0x7FFFFFFF;
struct Edge
{
int from, to, cap, flow;
Edge(int u, int v, int c, int f) :from(u), to(v), cap(c), flow(f){}
};
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn];
int s, t; void init()
{
for (int i = ; i < maxn; i++)
G[i].clear();
edges.clear();
}
void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge(from, to, cap, ));
edges.push_back(Edge(to, from, , ));
int w = edges.size();
G[from].push_back(w - );
G[to].push_back(w - );
}
bool BFS()
{
memset(vis, , sizeof(vis));
queue<int>Q;
Q.push(s);
d[s] = ;
vis[s] = ;
while (!Q.empty())
{
int x = Q.front();
Q.pop();
for (int i = ; i<G[x].size(); i++)
{
Edge e = edges[G[x][i]];
if (!vis[e.to] && e.cap>e.flow)
{
vis[e.to] = ;
d[e.to] = d[x] + ;
Q.push(e.to);
}
}
}
return vis[t];
}
int DFS(int x, int a)
{
if (x == t || a == )
return a;
int flow = , f;
for (int &i = cur[x]; i<G[x].size(); i++)
{
Edge e = edges[G[x][i]];
if (d[x]+ == d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>)
{
edges[G[x][i]].flow+=f;
edges[G[x][i] ^ ].flow-=f;
flow+=f;
a-=f;
if(a==) break;
}
}
if(!flow) d[x] = -;
return flow;
}
int dinic(int s, int t)
{
int flow = ;
while (BFS())
{
memset(cur, , sizeof(cur));
flow += DFS(s, INF);
}
return flow;
} int check(int limit)
{
memset(flag,,sizeof flag);
memset(se,,sizeof se);
for(int i=;i<=n;i++) if(p[i].t<=limit) flag[i]=; init(); s=; t=n+m+; int sum=; for(int i=;i<=m;i++)
{
bool fail=;
for(int j=;j<g[i].size();j++) if(flag[g[i][j]]==) fail=;
if(fail==) continue; for(int j=;j<g[i].size();j++) AddEdge(i,g[i][j]+m,INF); AddEdge(s,i,pro[i]);
sum=sum+pro[i];
} for(int i=;i<=n;i++) AddEdge(i+m,t,p[i].pay); return sum-dinic(s,t);
} int main()
{
//File();
scanf("%d",&T); int cas=;
while(T--)
{
scanf("%d%d%d",&n,&m,&L);
for(int i=;i<=m;i++) g[i].clear();
for(int i=;i<=n;i++) scanf("%d%d",&p[i].pay,&p[i].t);
for(int i=;i<=m;i++)
{
scanf("%d",&pro[i]);
int k; scanf("%d",&k);
while(k--)
{
int x; scanf("%d",&x);
g[i].push_back(x);
}
}
int left=,right=; int ans1=-,ans2=-;
while(left<=right)
{
int mid=(left+right)/;
int ppp=check(mid);
if(ppp>=L)
{
right=mid-;
ans1=mid;
ans2=ppp;
}
else
left=mid+;
}
printf("Case #%d: ",cas++);
if(ans1==-) printf("impossible\n");
else printf("%d %d\n",ans1,ans2);
}
return ;
}

HDU 5855 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. 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)

    Less Time, More profit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  3. HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online

    意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖 ...

  4. Hdu 5052 Yaoge’s maximum profit(树链剖分)

    题目大意: 给出一棵树.每一个点有商店.每一个商店都有一个价格,Yaoge每次从x走到y都能够在一个倒卖商品,从中得取利益.当然,买一顶要在卖之前.可是没次走过一条路,这条路上的全部商品都会添加一个v ...

  5. Yaoge’s maximum profit HDU - 5052

    Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  6. HDU 5855Less Time, More profit

    Less Time, More profit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

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

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

  8. HDU 1712 分组背包

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. ssi-uploader上传图片插件,点击选择文件按钮自动提交表单解决办法

    先介绍一下这款插件,然后再谈使用中可能遇到的问题 ssi-uploader是一个JQuery的图片上传插件,界面比较美观 github地址:https://github.com/ssbeefeater ...

  2. 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid

    [源码下载] 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid 作者:webabcd 介绍背 ...

  3. trie树模板(统计难题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  4. svn服务器搭建-SuSE Linux Enterprise Server 11 SP3

    svn存储版本数据也有2种方式: 1.bdb: 2.fsfs. 因为BDB方式在服务器中断时,有可能锁住数据(搞ldap时就深受其害,没法根治),所以还是FSFS方式更安全一点,我也选择这种方式.   ...

  5. angularjs 中的iframe 标签 ng-src 路径

    如果直接写路径到iframe标签里的ng-src中会出现报错: 解决方法: 1.ng里面有个属性是专门用来解决跨域问题的 $sce. 用法: $scope.someUrl = $sce.trustAs ...

  6. [转]numpy中的matrix矩阵处理

    今天看文档发现numpy并不推荐使用matrix类型.主要是因为array才是numpy的标准类型,并且基本上各种函数都有队array类型的处理,而matrix只是一部分支持而已. 这个转载还是先放着 ...

  7. 解码红外遥控信号——使用遥控器的按键来调节LED的亮度

    程序开始时,提示遥控键0~4的代码,然后程序通过设置LED的亮度来对被按下的按钮作出响应,以0关闭LED,1~4提供增加的亮度. 代码如下:(需要使用IRremote库,可在库管理中搜索该库进行下载后 ...

  8. WPS Office 二次开发简易教程。

    http://bbs.wps.cn/forum.php?mod=viewthread&tid=22004642

  9. Python3 md5加密

    import hashlibuser = 'jointwisdom'pwd = 'zhonghui123'm2 = hashlib.md5()m2.update(pwd.encode("ut ...

  10. css2和CSS3的background属性简写

    1.css2:background:background-color || url("") || no-repeat || scroll || 0 0;  css3:  backg ...