Gym - 100543L
Gym - 100543L
https://vjudge.net/problem/153854/origin
区间dp,要从区间长度为1开始dp
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 1010
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
long long T;
long long n,m;
struct node{
long long l;
long long r;
long long w;
}a[N];
long long b[N],id,Max;
long long f[N][N];
void in(long long &x){
long long y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(long long x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void clear(){
m=;
//memset(f,0,sizeof(f));
} int main(){
in(T);
while(T--){
clear();
in(n);
For(i,,n){
in(a[i].l);in(a[i].r);in(a[i].w);
b[++m]=a[i].l;
b[++m]=a[i].r;
}
sort(b+,b+m+);
m=unique(b+,b+m+)-b-;
For(i,,n){
a[i].l=lower_bound(b+,b+m+,a[i].l)-b;
a[i].r=lower_bound(b+,b+m+,a[i].r)-b;
}
For(len,,m)
For(l,,m-len+){
int r=l+len-;
id=;
For(i,,n)
if(a[i].l>=l&&a[i].r<=r)
if(id==||a[i].w>a[id].w)
id=i;
if(id==){
f[l][r]=;
continue;
}
f[l][r]=inf;
For(i,a[id].l,a[id].r)
f[l][r]=min(f[l][r],f[l][i-]+f[i+][r]+a[id].w);
}
o(f[][m]);p('\n');
}
return ;
}
Gym - 100543L的更多相关文章
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- Hadoop配置lzo
编译: 0. 环境准备 maven(下载安装,配置环境变量,修改sitting.xml加阿里云镜像) gcc-c++ zlib-devel autoconf automake libtool 通过yu ...
- Last_SQL_Error: Error 'Can't drop database
此文办法只用应急, 别的办法我还没想到, 文章是Copy来的 MySQL主从同步报错排错结果及修复过程之:Slave_SQL_Running: No 起因调查: 收到大量邮件报警想必事出有因,就问同 ...
- Flink on YARN(下):常见问题与排查思路
Flink 支持 Standalone 独立部署和 YARN.Kubernetes.Mesos 等集群部署模式,其中 YARN 集群部署模式在国内的应用越来越广泛.Flink 社区将推出 Flink ...
- [JZOJ 5778] 没有硝烟的战争
思路: 记\(dp[i][j] = 0/1\)来表示第\(i\)个动物报的数字是\(j\),有无必胜策略. 判断有没有转移就可以了. 输出直接对于每一只动物,看\(dp[i][1->k]\)有没 ...
- TStringList常用操作
TStringList常用操作 //TStringList 常用方法与属性: var List: TStringList; i: Integer; begin List := TStringList. ...
- python基础-基础知识(包括:函数递归等知识)
老男孩 Python 基础知识练习(三) 1.列举布尔值为 False 的值空,None,0, False, ", [], {}, () 2.写函数:根据范围获取其中 3 和 7 整除的所有 ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- Python编码decode和encode
常见编码介绍: GB2312编码:适用于汉字处理.汉字通信等系统之间的信息交换;GBK编码:是汉字编码标准之一,是在 GB2312-80 标准基础上的内码扩展规范,使用了双字节编码ASCII编码:是对 ...
- <前端>简单实现开心网注册
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- USACO 2009 Open Grazing2 /// DP+滚动数组oj26223
题目大意: 输入n,s:n头牛 s个栅栏 输入n头牛的初始位置 改变他们的位置,满足 1.第一头与最后一头的距离尽量大 2.相邻两头牛之间的距离尽量满足 d=(s-1)/(n-1),偏差不超过1 3. ...