http://www.lydsy.com/JudgeOnline/problem.php?id=3997

偏序集,看上一篇随笔

我们要求最少路径覆盖,可以等价于求最大独立集。

我们要找到一个权值和最大的点集$S$,使得对于点集中任意两个点$点i$和$点j$,使得$点i$不能到$点j$,就是要求$点i$严格在$点j$的右上方或左下方。
用DP可以在$O(N^2)$内解决。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define fill(a,l,r,v) fill(a+l,a+r+1,v)
#define re(i,a,b) for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} inline int sgn(DB x){if(abs(x)<1e-)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const int maxn=; int n,m;
int mp[maxn+][maxn+];
LL f[maxn+][maxn+]; int main()
{
freopen("bzoj3997.in","r",stdin);
freopen("bzoj3997.out","w",stdout);
int i,j;
for(int Case=gint();Case;Case--)
{
n=gint();m=gint();
re(i,,n)re(j,,m)mp[i][j]=gint();
mmst(f,);
re(i,,n)red(j,m,)f[i][j]=max(f[i-][j+]+mp[i][j],max(f[i][j+],f[i-][j]));
cout<<f[n][]<<endl;
}
return ;
}

bzoj3997[TJOI2015]组合数学的更多相关文章

  1. BZOJ3997: [TJOI2015]组合数学(网络流)

    3997: [TJOI2015]组合数学 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 405  Solved: 284[Submit][Status ...

  2. BZOJ3997 TJOI2015组合数学(动态规划)

    copy: Dilworth定理:DAG的最小链覆盖=最大点独立集 最小链覆盖指选出最少的链(可以重复)使得每个点都在至少一条链中 最大点独立集指最大的集合使集合中任意两点不可达 此题中独立的定义即是 ...

  3. [BZOJ3997][TJOI2015]组合数学(Dilworth定理+DP)

    题目名字是什么就不能往那方面想. 每个点拆成a[i][j]个,问题变为DAG最小路径覆盖,由Dilworth定理转成最长反链. 使用Dilworth定理的时候要注意那些点之间有边,这里任意一个点和其右 ...

  4. bzoj3997[TJOI2015]组合数学(求最长反链的dp)

    组合数学 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走.问至少走多少次才能将财宝捡完.此对此问题变形,假设每个格子中有好多财宝,而每一次经过一个格子至多只能捡走一块财宝,至少走 ...

  5. bzoj千题计划298:bzoj3997: [TJOI2015]组合数学

    http://www.lydsy.com/JudgeOnline/problem.php?id=3997 最小链覆盖=最长反链长度 所以题目等价于寻找一条从右上角到左下角的最长路 #include&l ...

  6. BZOJ3997:[TJOI2015]组合数学(DP,Dilworth定理)

    Description 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走.问至少走多少次才能将财宝捡完.此对此问题变形,假设每个格子中有好多财宝,而每一次经过一个格子至多只能捡走一 ...

  7. BZOJ3997 [TJOI2015]组合数学 【Dilworth定理】

    题目 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走.问至少走多少次才能将财宝捡完.此对此问题变形,假设每个格子中有好多财宝,而每一次经过一个格子至多只能捡走一块财宝,至少走多少 ...

  8. 【BZOJ3997】[TJOI2015]组合数学(动态规划)

    [BZOJ3997][TJOI2015]组合数学(动态规划) 题面 BZOJ 洛谷 题解 相当妙的一道题目.不看题解我只会暴力网络流 先考虑要求的是一个什么东西,我们把每个点按照\(a[i][j]\) ...

  9. 【BZOJ3997】[TJOI2015]组合数学 最长反链

    [BZOJ3997][TJOI2015]组合数学 Description 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走.问至少走多少次才能将财宝捡完.此对此问题变形,假设每个格 ...

随机推荐

  1. get client machine name

    System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;

  2. java web mvc思想介绍

    1.首先简介一下什么是MVC思想. 在百度百科里面对MVC的说明,MVC全名是Model View Controller.是模型(model)-视图(view)-控制器(controller)的缩写. ...

  3. 第二节,CCSpriteBatchNode CCSpriteFrameCache

    1,CCSpriteBatchNode 精灵集合类 其中Batch的英文含义是一批,一群的意思.他的对象常常包含了许多的精灵对象,这些精灵对象有一个共同的特点,那就是使用同一张文理图片.虽然是同一个纹 ...

  4. [RxJS] Creation operators: fromEventPattern, fromEvent

    Besides converting arrays and promises to Observables, we can also convert other structures to Obser ...

  5. JAVA - Comparable接口 与 Comparator接口

      Similarities:Both are custom ways to compare two objects.Both return an int describing the relatio ...

  6. There is already an open DataReader associated with this Connection which must be closed first

    使用MVC4 EF Linq获取foreach列表循环的时候遇到了如下的问题:报错提示 There is already an open DataReader associated with this ...

  7. C++关联容器<map>简单总结

    C++关联容器<map>简单总结 map提供大小可变的关联容器,基于关联键值高效检索元素值.当你处理键值对的数据是,都可以考虑使用map关联容器. 特点: 大小可变的关联容器,基于关联键值 ...

  8. state模式理解

    state模式应用场景 条件判断很多的情况 比如有很多if else语句:switch case语句等等. 如果以后业务越来越复杂,条件判断有100多个,每种条件的处理逻辑很复杂,不止一个业务逻辑会重 ...

  9. PL/SQL客户端安装配置说明

    一.电脑安装了多个Oracle客户端时,需要设定pl/sql 中的home 二.配置环境变量: (打开环境变量配置界面操作:我的电脑---属性---高级---环境变量,在系统变量部分新建或编辑即可.w ...

  10. c - 字符串的拼接.

    完整代码: #include <stdio.h> #include <string.h> #include <malloc.h> #define TRUE 1 #d ...