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 ...
随机推荐
- AtCoder Beginner Contest 132 E - Hopscotch Addict
bfs 位置+状态 just need to calculate min value(only it is useful), so O(1*x) 挺有趣的一道题... #include <cst ...
- 十一. for of
const fruits = ['Apple','Banana','Orange','Mango']; es5: 可读性差 for(let i=0; i < fruits.length; i + ...
- mysql 监控及优化——转载自http://www.cnblogs.com/suansuan/
1.Mysql连接数 Mysql默认最大连接数为100. 设置Mysql的最大连接数,在Mysql的配置文件中增加: max_connections = 1000 #Mysql的最大连接数,默认如 ...
- [TJOI 2018]游园会
题意:求NOI的合法串... 思路: 首先这个似乎和后缀自动机没关系(话说TJ不考后缀自动机??),其实就是一个\(DP\)套\(DP\),考虑如果不看兑奖串就是一个LCS,当出现时多记一维即可. # ...
- ImageMagick convert多张照片JPG转成pdf格式,pdfunite合并PDF文件
在认识ImageMagick之前,我***的图像浏览软件是KuickShow,截图软件是KSnapShot,这两款软件都是KDE附带的软件,用起来也是蛮方便的.在一次偶然的机会中,我遇到了Imag ...
- java中 ++a 与 a++ 的区别
public static void main(String[] args) { int a = 5; a ++; System.out.println(a); int b = 5; ++ b; Sy ...
- Python - 作为浅拷贝的list对象乘法
运行下面这段代码 # !/usr/bin/env python3 # -*- coding=utf-8 -*- temp_a = [[0]*2]*3 temp_b = [[0]*2 for i in ...
- 第四周课堂笔记1th
函数 关键字def 函数名加括号 是调用函数 Return 相当于给函数算完之后给予另一个返回值 返回的是元组 如果return后没写返回none Return在函数中可以结束整 ...
- 2019-8-31-dotnet-通过-WMI-获取系统启动的服务
title author date CreateTime categories dotnet 通过 WMI 获取系统启动的服务 lindexi 2019-08-31 16:55:59 +0800 20 ...
- Amazon S3和EBS的区别