P4474 王者之剑
题目大意
n*m的带权网格,任意选择起点
开始时刻为0秒。以下操作,每秒按顺序执行
- 在第i秒开始的时候,在方格(x,y)上,获得(x,y)的值
- 在偶数秒,周围四格的值清零
- 每秒可选择不动或走一格
求最大值
易证:选择获得某格上的值时,周围四格就不能获得了------二分图最大点权独立集
网格------奇偶分类
网络流跑最小割
My complete code:
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- #include<string>
- #include<queue>
- using namespace std;
- typedef long long LL;
- const LL maxn=500000;
- const LL inf=0x3f3f3f3f;
- const LL dx[5]={0,-1,0,1,0};
- const LL dy[5]={0,0,1,0,-1};
- inline LL read(){
- LL x=0,f=1; char c=getchar();
- while(c<'0'||c>'9'){
- if(c=='-') f=-1; c=getchar();
- }
- while(c>='0'&&c<='9'){
- x=x*10+c-'0'; c=getchar();
- }return x*f;
- }
- struct node{
- LL to,next,flow;
- }dis[maxn];
- LL num=-1,s,t,n,m,ans;
- LL head[maxn],dep[maxn];
- inline void Add(LL u,LL v,LL flow){
- dis[++num]=(node){v,head[u],flow}; head[u]=num;
- }
- inline bool Bfs(){
- memset(dep,0,sizeof(dep));
- queue<LL> que;
- que.push(s);
- dep[s]=1;
- while(que.size()){
- LL u=que.front();
- que.pop();
- for(LL i=head[u];i!=-1;i=dis[i].next){
- LL v=dis[i].to;
- if(!dep[v]&&dis[i].flow){
- dep[v]=dep[u]+1;
- que.push(v);
- }
- }
- }
- return dep[t];
- }
- LL Dfs(LL u,LL flow){
- if(u==t)
- return flow;
- LL tmp=flow;
- for(LL i=head[u];i!=-1;i=dis[i].next){
- LL v=dis[i].to;
- if(dep[v]==dep[u]+1&&dis[i].flow&&tmp){
- LL now=Dfs(v,min(tmp,dis[i].flow));
- if(now){
- dis[i].flow-=now;
- dis[i^1].flow+=now;
- tmp-=now;
- }else
- dep[v]=inf;
- }
- }
- return flow-tmp;
- }
- inline LL Dinic(){
- LL sum=0;
- while(Bfs())
- sum+=Dfs(s,inf);
- return sum;
- }
- int main(){
- n=read(); m=read();
- s=0; t=n*m+1;
- memset(head,-1,sizeof(head));
- for(LL i=1;i<=n;++i)
- for(LL j=1;j<=m;++j){
- LL val=read();
- ans+=val;
- if((i+j)&1){
- Add(s,(i-1)*m+j,val);
- Add((i-1)*m+j,s,0);
- }else{
- Add((i-1)*m+j,t,val);
- Add(t,(i-1)*m+j,0);
- }
- }
- for(LL i=1;i<=n;++i)
- for(LL j=1;j<=m;++j){
- if((i+j)&1){
- for(LL k=1;k<=4;++k){
- LL nx=i+dx[k],ny=j+dy[k];
- if(nx<1||nx>n||ny<1||ny>m)
- continue;
- Add((i-1)*m+j,(nx-1)*m+ny,inf);
- Add((nx-1)*m+ny,(i-1)*m+j,0);
- }
- }
- }
- ans-=Dinic();
- printf("%lld",ans);
- return 0;
- }
P4474 王者之剑的更多相关文章
- 洛咕 P4474 王者之剑
宝石只能在偶数秒取到,假设有一个宝石在奇数秒取到了,那么上一秒是偶数秒,在上一秒的时候这里的宝石就没了. 相邻的两个宝石不能同时取,很显然,先取一块,那么这是偶数秒,取完了这一块之后相邻的都没了. 只 ...
- 【BZOJ-1324】Exca王者之剑 最小割
1324: Exca王者之剑 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 483 Solved: 248[Submit][Status][Disc ...
- BZOJ1324: Exca王者之剑
1324: Exca王者之剑 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 256 Solved: 131[Submit][Status] Desc ...
- 图论(二分图最大权独立点集):COGS 2051. 王者之剑
2051. 王者之剑 ★★★☆ 输入文件:Excalibur.in 输出文件:Excalibur.out 简单对比 时间限制:1 s 内存限制:256 MB [题目描述] 这是在阿尔托 ...
- BZOJ 1324: Exca王者之剑
1324: Exca王者之剑 Description Input 第一行给出数字N,M代表行列数.N,M均小于等于100 下面N行M列用于描述数字矩阵 Output 输出最多可以拿到多少块宝石 Sam ...
- [COGS 2051] 王者之剑
Saber大法吼 2051. 王者之剑 ★★★☆ 输入文件:Excalibur.in 输出文件:Excalibur.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述 ...
- [bzoj1324]Exca王者之剑_最小割
Exca王者之剑 bzoj-1324 题目大意:题目链接. 注释:略. 想法: 最小割经典模型. 所有格子向源点连权值为格子权值的边. 将棋盘黑白染色后白点反转源汇. 如果两个格子相邻那么黑点向白点连 ...
- 【BZOJ】【1324】王者之剑
网络流/二分图最大点权独立集 Amber(胡伯涛)论文<最小割模型在信息学竞赛中的应用>中的例题…… 感觉这个好神啊,果然是一切皆为网络流……这转化太神奇了 /************** ...
- bzoj 1324 Exca王者之剑(黑白染色,最小割)
[题意] 两相邻点不能同时选,选一个点集使得权值和最大. 出题人语文好... [思路] 将图进行黑白二染色,然后构建最小割模型. [代码] #include<set> #include&l ...
随机推荐
- windows核心编程 DLL技术 【转】
注:本文章转载于网络,源地址为:http://blog.csdn.net/ithzhang/article/details/7051558 本篇文章将介绍DLL显式链接的过程和模块基地址重定位及模块绑 ...
- newlisp HTTP Basic Authentication
HTTP Basic Authentication原来很easy,參考文档:http://zh.wikipedia.org/wiki/HTTP%E5%9F%BA%E6%9C%AC%E8%AE%A4%E ...
- 【Python】使用制表符换行符来添加空白
在编程中,在打印时,有时候需要显示出来的数据看着舒服一点,那么使用制表符(\t).换行符(\n)即可轻松实现 >>> print('zhangsan')zhangsan 加入制表符后 ...
- RelativeLayout布局(仅在RelativeLayout中有效)
在父亲布局的相对位置 android:layout_alignParentLeft="true" //在布局左边 android:layout_alignParentRig ...
- 用递归法将一个整数n转换成字符串。
用递归法将一个整数n转换成字符串. 比如,输入483,应输出字符串"483".n的位数不确定,能够是随意位数的整数. #include "stdafx.h" # ...
- leetCode 61.Rotate List (旋转链表) 解题思路和方法
Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For ex ...
- MVC总结--MVC简单介绍以及和WebForm差别
什么是MVC MVC(Model-View-Controller.模型-视图-控制器模式)用于表示一种软件架构模式.它把软件系统分为三个基本部分:模型(Model),视图(View)和控制器(Cont ...
- OpenCV视频读取播放,视频转换为图片
转载请注明出处!!! http://blog.csdn.net/zhonghuan1992 OpenCV视频读取播放,视频转换为图片 介绍几个有关视频读取的函数: VideoCapture::Vide ...
- HDU1845Jimmy’s Assignment(无向图,最大匹配)
题意:就是求最大匹配 #include<cstdio> #include<iostream> #include<algorithm> #include<cma ...
- MagicalRecord使用教程【转载】
原文地址:http://www.ithao123.cn/content-96403.html 下面是在xcode5.1下ARC环境中的使用教程 1. 将 MagicalRecord 文件夹拖入到工程文 ...