poj 1201 Intervals
来源:互联网 发布:电视剧硅谷中的算法 编辑:程序博客网 时间:2024/06/04 18:31
题目大意
有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai,bi]这个区间的整数至少有ci个。如果存在这样的序列,请求出满足题目要求的最短的序列长度是多少。如果不存在则输出 -1。
输入
第一行包括一个整数n,表示区间个数,以下n行每行描述这些区间,第i+1行三个整数ai,bi,ci,由空格隔开,其中0<=ai<=bi<=50000 而且 1<=ci<=bi-ai+1。
输出
一行,输出满足要求的序列的长度的最小值。
分析
无路赛
代码
const maxe=60000; maxv=1000000;type arr=record x,y,w,next:longint;end;var n,m,s:longint; nm:longint; a:array[0..maxv] of arr; d:array[0..maxe] of longint; v1:array[0..maxe] of longint; ls:array[0..maxe] of longint; stick:array[0..maxv] of longint; head,tail:longint; x,y,w:longint; i,j,k:longint; flag:boolean; flaj:array[0..maxe] of longint; max:longint;procedure relax(u,v,w:longint);begin if d[u]+w<d[v] then begin d[v]:=d[u]+w; if v1[v]=0 then begin head:=head+1; stick[head]:=v; flaj[v]:=flaj[v]+1; v1[v]:=1; end; end;end;procedure bellman;var i,j:longint;begin head:=1; stick[head]:=1; v1[1]:=1; repeat j:=stick[head]; i:=ls[stick[head]]; head:=head-1; while i<>0 do with a[i] do begin relax(x,y,w); if flaj[y]>n then begin flag:=true; exit; end; i:=next; end; v1[j]:=0; until head=0;end;procedure add(x,y,w:longint);begin nm:=nm+1; a[nm].x:=x; a[nm].y:=y; a[nm].w:=w; a[nm].next:=ls[x]; ls[x]:=nm;end;begin readln(m); fillchar(a,sizeof(a),0); fillchar(d,sizeof(d),$7f); n:=0; max:=d[1]; for j:=1 to m do begin read(x,y,w); add(x,y+1,-w); //add(y+1,x,y-x+1); if if y>n then n:=y; end; for j:=0 to n+1 do begin add(j,j+1,0); add(j+1,j,1); end; m:=nm; n:=n+1; d[1]:=0; flag:=false; bellman; if flag then writeln('-1') else write(-d[n]);end.
0 0
- POJ 1201 Intervals
- poj 1201 Intervals
- POJ 1201 Intervals
- POJ 1201 Intervals
- poj 1201 Intervals
- poj 1201 Intervals
- POJ 1201 Intervals
- POJ 1201 Intervals
- poj 1201 -Intervals
- Poj 1201 Intervals
- POJ 1201 Intervals
- POJ 1201 Intervals
- POJ 1201-Intervals
- POJ-1201-Intervals
- poj 1201 Intervals
- poj 1201 Intervals
- poj 1201 Intervals
- poj 1201 Intervals
- 有向图与拓扑排序
- 【HPU 1192 Sequence】+ 状态压缩 +组合数学
- 找出一个字符串中最长回文子串
- html常识(与css、javascript三者的关联关系)
- 能否在一个构造器中调用另一个构造器
- poj 1201 Intervals
- oracle的增删改插和子查询
- 设计模式笔记——策略设计模式
- ViewFlipper 视图容器
- HDU 3642 Get The Treasury 【线段树】【扫描线】
- opencv如何进行摄像头标定
- hbase安装说明
- opencv学习(十四)之图像颜色通道分离和融合
- Java金融信息交换引擎 QuickFIX/J