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 ...
随机推荐
- Maven - Scope区别
依赖的Scope scope定义了类包在项目的使用阶段.项目阶段包括: 编译,运行,测试和发布. 分类说明 compile 默认scope为compile,表示为当前依赖参与项目的编译.测试和运行阶段 ...
- oracle将查询结果横转纵
SELECT '残疾人|民政|综合治理|计划生育|物业监管|安全生产|环境类|司法信访|党建|社会组织|文化体育|社保' D , '53|52|51|50|49|48|47|5|4|3|2|1' g ...
- 期望dp+高斯消元优化——uvalive4297好题
非常好的题!期望+建矩阵是简单的,但是直接套高斯消元会T 所以消元时要按照矩阵的形态 进行优化 #include<bits/stdc++.h> using namespace std; ; ...
- springboot2.x jpa接入多数据源
环境:springboot 2.1.4 数据源引入方式 数据源一 @Configuration @EnableTransactionManagement @EnableJpaRepositories( ...
- 常用css初始化样式(淘宝)
最简单粗暴的css初始化样式就是:*{padding:0:margin:0}(不推荐) 淘宝的样式初始化: body, h1, h2, h3, h4, h5, h6, hr, p, blockquot ...
- 图片压缩(js压缩,底部有vue压缩图片依赖使用的教程链接)
directTurnIntoBase64(fileObj, callback) { var r = new FileReader(); // 转成base64 r.onload = function( ...
- 固定定位fixed,绝对定位absolute,相对定位relative;以及overflow
固定定位position:fixed /*固定定位 1.定位属性值:fixed 2.在页面中不再占位(浮起来了) 3.一旦定位后,定位的布局方位 top.bottom.left.right都能参与布局 ...
- POJ-3264-Balanced Lineup-线段树模板题-查询区间内最大值和最小值之差
For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One d ...
- 9个搜索引擎优化(SEO)最佳实践
作为网页设计师,搜索引擎优化重要吗?我们知道,网站设计是把屏幕上平淡无奇变成令人愉快的美感,更直观地辨认信息.这也是人与人之间在沟通想法,这样的方式一直在演变. 1. 网站结构 对于搜索引擎优化,网站 ...
- 16.ajax_case08
# 抓取简书博客总阅读量 # https://www.jianshu.com/u/130f76596b02 import requests import json import re from lxm ...