zoj2332:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2332

题意:这一道题的题意,我看了很久,也没有看明白,最终还是理解错了。题目的意思是有n*m种石头,有n种形状,m种颜色。一个人对于每一种形状有一定的容忍度,另外一个人对于每一种颜色有一定容忍度,然后问你能把这些石头分给这两个人,使得每个人能够满意。

题解:每一种石头作为一个点,与源点连边,边的容量就是石头的数量,然后每一行作为一个点,对应每一种形状的,容量是INF,然后是每一列一个点,与宝石连接,INF,然后每个行与BF连接,就是每一种形状的容忍度,每一列与GF连接,就是每一种颜色的容忍度,然后BF,GF与汇点连接,INF。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#define INF 100000000
using namespace std;
const int N=;
const int M=;
struct Node{
int v;
int f;
int next;
}edge[M];
int n,m,u,v,cnt,sx,ex;
int head[N],pre[N];
int mp[N][N],a1[N],a2[N];
void init(){
cnt=;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w){
edge[cnt].v=v;
edge[cnt].f=w;
edge[cnt].next=head[u];
head[u]=cnt++;
edge[cnt].f=;
edge[cnt].v=u;
edge[cnt].next=head[v];
head[v]=cnt++;
}
bool BFS(){
memset(pre,,sizeof(pre));
pre[sx]=;
queue<int>Q;
Q.push(sx);
while(!Q.empty()){
int d=Q.front();
Q.pop();
for(int i=head[d];i!=-;i=edge[i].next ){
if(edge[i].f&&!pre[edge[i].v]){
pre[edge[i].v]=pre[d]+;
Q.push(edge[i].v);
}
}
}
return pre[ex]>;
}
int dinic(int flow,int ps){
int f=flow;
if(ps==ex)return f;
for(int i=head[ps];i!=-;i=edge[i].next){
if(edge[i].f&&pre[edge[i].v]==pre[ps]+){
int a=edge[i].f;
int t=dinic(min(a,flow),edge[i].v);
edge[i].f-=t;
edge[i^].f+=t;
flow-=t;
if(flow<=)break;
} }
if(f-flow<=)pre[ps]=-;
return f-flow;
}
int solve(){
int sum=;
while(BFS())
sum+=dinic(INF,sx);
return sum;
}
int main() {
int T,k,temp,sum,d,t1,t2,t3,t4,tt=;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
init();sum=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%d",&temp);
sum+=temp;
add(,(i-)*m+j,temp);
} scanf("%d",&d);
for(int i=;i<=d;i++){
scanf("%d%d%d%d",&t1,&t2,&t3,&t4);
t2++;t4++;
add(t1*m+t2,t3*m+t4,INF);
add(t3*m+t4,t1*m+t2,INF);
}
for(int i=;i<=n;i++){
scanf("%d",&temp);
for(int j=;j<=m;j++){
add((i-)*m+j,n*m+i,INF);
}
add(n*m+i,n*m+m+n+,temp);
}
for(int i=;i<=m;i++){
scanf("%d",&temp);
for(int j=;j<=n;j++){
add((j-)*m+i,n*m+n+i,INF);
}
add(n*m+n+i,n*m+m+n+,temp);
}
add(n*m+n+m+,n*m+n+m+,INF);
add(n*m+n+m+,n*m+n+m+,INF);
sx=,ex=n*m+n+m+;
int td=solve();
if(td==sum)printf("Yes\n");
else
printf("No\n");
}
return ;
}

Gems的更多相关文章

  1. Unable to download data from http://ruby.taobao.org/ & don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

    安装cocoapods,记录两个问题! 1.镜像已经替换成了 http://ruby.taobao.org/, 还是不能不能安装cocoapods, 报错:Unable to download dat ...

  2. ACM: Racing Gems - 最长递增序列

    Racing Gems   You are playing a racing game.  Your character starts at the x axis (y = 0) and procee ...

  3. UVALive - 7374 Racing Gems 二维非递减子序列

    题目链接: http://acm.hust.edu.cn/vjudge/problem/356795 Racing Gems Time Limit: 3000MS 问题描述 You are playi ...

  4. uva 10274 Fans and Gems(隐式图搜索+模拟)

    Fans and Gems Input: Standard Input Output: Standard Output Tomy's fond of a game called 'Fans and G ...

  5. hdu 4778 Gems Fight! 博弈+状态dp+搜索

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...

  6. ruby gem源更换国内源gems.ruby-china.org数据源

    gem sources -l gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ 更新缓存 ge ...

  7. hdu 6199 沈阳网络赛---gems gems gems(DP)

    题目链接 Problem Description Now there are n gems, each of which has its own value. Alice and Bob play a ...

  8. hdu 4778 Gems Fight! 状态压缩DP

    Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)T ...

  9. Error fetching https://gems.ruby-china.org/: bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz) 报错解决办法

    执行换源操作 gem source -a https://gems.ruby-china.org/ 时报错: Error fetching https://gems.ruby-china.org/: ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. NVMe 与 AHCI

    http://elf8848.iteye.com/blog/1731274 AHCI: NCQ技术,600MB/S,一个队列,每个队列32个指令 NVME:65000个队列,每个队列65000指令,3 ...

  2. SCTP 关联的建立和终止

    与TCP一样,SCTP也是面向连接的,因而也有关联的建立与终止的握手过程.不过SCTP的握手过程不同于TCP. 四路握手 建立一个SCTP关联的时候会发生下述情形(类似于TCP). (1)服务器必须准 ...

  3. centos 6.3 编译安装 nginx +mysql + php

    这篇文章是对另一篇文章的整理,作为记录收藏 1,配置防火墙,开启80端口.3306端口 配置iptables,开启80端口.3306端口 vi /etc/sysconfig/iptables -A I ...

  4. homework做了些什么?

    第一步:get_new_guid_uid_pairs_{$ymd} 参数是时间和100上的文件. 那么100上的文件是从哪里来的呢? 我们进入到100机器上,打开root权限下的cron,看到如下内容 ...

  5. 学习java随笔第五篇:流程控制

    条件语句 if(表达式){方法体}else if(表达体)else{方法体} 简写形式:if... 一般形式:if...else... 完整形式:if...else if...else 分支语句 sw ...

  6. 深入探讨C#中Socket一次性搞定消息发送

    转载自:http://tech.chinaunix.net/a2010/0909/1101/000001101396.shtml     [IT168 技术文档]最近浏览了几篇有关Socket发送消息 ...

  7. JS 頁面實時更新時間

    function startTime() { var today = new Date(); //定义日期对象 var yyyy = today.getFullYear(); //通过日期对象的get ...

  8. Visual C++ 编程实现Soft AP (HostedNetwork / 承载网络) 功能

    从Windows 7开始,微软在操作系统中加入的Soft AP功能,使用户能够通过无线网卡,开启虚拟AP,从而实现网络共享.Soft AP又称HostedNetwork(承载网络),在Windows ...

  9. ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)

    题目描述 We know thatIvan gives Saya three problems to solve (Problem F), and this is the firstproblem. ...

  10. 速卖通api--发起授权

    <? $reqURL_onLine = "https://gw.api.alibaba.com/openapi/http/1/system.oauth2/getToken/494739 ...