LIS ZOJ - 4028
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4028
memset超时
这题竟然是一个差分约束
好吧呢
对于每一个a[i], l <= a[i] <= r
那么设一个源点s
使 l <= a[i] - s <= r 是不是就能建边了
然后对于每一个f[i]
如果前面有一个相等的f[j]
则肯定 a[i] <= a[j] 又能建边了
根据LIS的传递关系
对于每个f[i] 肯定是由上一个等级的传递过来的
即 a[i] > a[j] 是不是又能建边了
不会建边?
请移步: https://www.cnblogs.com/WTSRUVF/p/9153758.html
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int head[maxn], vis[maxn];
LL d[maxn];
int cnt;
int n, m, s;
int ans[maxn]; struct node
{
int u, v, next;
int w;
}Node[]; void add(int u, int v, int w)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].w = w;
Node[cnt].next = head[u];
head[u] = cnt++;
} void init()
{
for(int i = ; i <= n + ; i++)
{
head[i] = -;
ans[i] = ;
vis[i] = ;
d[i] = INF;
}
cnt = ;
} bool spfa()
{
deque<int> Q;
Q.push_front(s);
d[s] = ;
vis[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop_front();
vis[u] = ;
for(int i = head[u]; i != -; i = Node[i].next)
{
int v = Node[i].v;
if(d[v] > d[u] + Node[i].w)
{
d[v] = d[u] + Node[i].w;
if(!vis[v])
{
if(Q.empty()) Q.push_front(v);
else if(d[v] < d[Q.front()]) Q.push_front(v);
else Q.push_back(v);
vis[v] = ;
if(++ans[v] > n) return ;
}
}
}
}
return ;
} int pre[maxn]; int main()
{
int T;
rd(T);
while(T--)
{ rd(n);
init();
s = n + ;
mem(pre, );
for(int i = ; i <= n; i++)
{
int f;
rd(f);
if(pre[f]) add(pre[f], i, );
if(f > ) add(i, pre[f - ], -);
pre[f] = i;
}
for(int i = ; i <= n; i++)
{
int l, r;
rd(l), rd(r);
add(s, i, r);
add(i, s, -l);
}
spfa();
for(int i = ; i <= n; i++)
{
if(i != ) printf(" ");
printf("%lld", d[i]); printf("\n");
} } return ;
}
LIS ZOJ - 4028的更多相关文章
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- ZOJ 1076 Gene Assembly(LIS+路径打印 贪心)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76 题目大意:在一个DNA上,给定许多基因的起始位置和结束位置,求出这 ...
- ZOJ 1076 Gene Assembly LIS
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76 题目大意: 题目前面都是废话. 给你一串基因,然后给你上面的外显子的起始和终 ...
- ZOJ 刷题记录 (。・ω・)ノ゙(Progress:31/50)
[热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ...
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
- 最长公共子序列(LCS)、最长递增子序列(LIS)、最长递增公共子序列(LICS)
最长公共子序列(LCS) [问题] 求两字符序列的最长公共字符子序列 问题描述:字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- Lis日常维护
1.[问题]护士站打印LIs条码,出来是PDF格式的 [解决]在文件夹Client\NeusoftLis\Xml\Print.xml中把BarcodePrint Name的值改成安装的斑马打印机名(不 ...
- uva10635 LIS
Prince and PrincessInput: Standard Input Output: Standard Output Time Limit: 3 Seconds In an n x n c ...
随机推荐
- 配置CLion作为Qt5开发环境
使用Qt进行程序开发时QtCreator总是不二之选.作为老牌IDE在提供了强大的功能同时也对Qt的支持做了许多优化.如果没有特别的原因你应该使用它. 然而一个顺手的工具将会极大得提升生产效率,而如果 ...
- AspNetCore 基于AOP实现Polly的使用
前言 说起AOP,其实我们在做MVC/API 的时候应该没少接触,比如说各种的Fitter 就是典型的AOP了. 本来在使用Polly的时候我最初的打算是使用过滤器来实现的,后来发现实现起来相当的 ...
- 折腾Java设计模式之备忘录模式
原文地址:折腾Java设计模式之备忘录模式 备忘录模式 Without violating encapsulation, capture and externalize an object's int ...
- 迭代器模式 Iterator 行为型 设计模式(二十)
迭代器模式(Iterator) 走遍天下,世界那么大,我想去看看 在计算机中,Iterator意为迭代器,迭代有重复的含义,在程序中,更有“遍历”的含义 如果给定一个数组,我们可以通过for循 ...
- vue 使用定时器setInterval
来自:https://www.jianshu.com/p/180957762852 侵删 beforeMount() { //车辆进出设置定时器,每3秒刷新一次 var self = this; cl ...
- typescript中的接口
说到接口:在面向对象的编程中,接口是一种规范的定义,它定义了行为和动作的规范,在程序设计里面,接口起到一种限制和规范的作用.接口定义了某一批类所需要遵守的规范,接口不关心这些类的内部状态数据,也不关心 ...
- uboot的启动过程-FDT
uboot的启动过程,省略了汇编部分之后,第一个执行函数是board_init_f(),在uboot/common目录的board_f.c中 board_init_f函数,首先初始化了全局数据 # ...
- Delphi 项目配置选项
打开项目设置窗口: 通过菜单:项目>选项 快捷键 :Shift+Ctrl+F11 Delphi编译器选项说明 Conditional defines 指定条件编译器指令中引用的符号. O ...
- Runnable和Callable之间的区别
Runnable和Callable之间的区别 1.Runnable任务执行后没有返回值:Callable任务执行后可以获得返回值 2.Runnable的方法是run(),没有返回值:Callable的 ...
- bilibili用户信息全栈爬取