青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

hdu3440(差分約束)

題目網址: http://acm.hdu.edu.cn/showproblem.php?pid=3440 

House Man

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 446    Accepted Submission(s): 157


Problem Description
In Fuzhou, there is a crazy super man. He can’t fly, but he could jump from housetop to housetop. Today he plans to use N houses to hone his house hopping skills. He will start at the shortest house and make N-1 jumps, with each jump taking him to a taller house than the one he is jumping from. When finished, he will have been on every house exactly once, traversing them in increasing order of height, and ending up on the tallest house.
The man can travel for at most a certain horizontal distance D in a single jump. To make this as much fun as possible, the crazy man want to maximize the distance between the positions of the shortest house and the tallest house.
The crazy super man have an ability—move houses. So he is going to move the houses subject to the following constraints:
1. All houses are to be moved along a one-dimensional path.
2. Houses must be moved at integer locations along the path, with no two houses at the same location.
3. Houses must be arranged so their moved ordering from left to right is the same as their ordering in the input. They must NOT be sorted by height, or reordered in any way. They must be kept in their stated order.
4. The super man can only jump so far, so every house must be moved close enough to the next taller house. Specifically, they must be no further than D apart on the ground (the difference in their heights doesn't matter).
Given N houses, in a specified order, each with a distinct integer height, help the super man figure out the maximum possible distance they can put between the shortest house and the tallest house, and be able to use the houses for training.
 

Input
In the first line there is an integer T, indicates the number of test cases.(T<=500)
Each test case begins with a line containing two integers N (1 ≤ N ≤ 1000) and D (1 ≤ D ≤1000000). The next line contains N integer, giving the heights of the N houses, in the order that they should be moved. Within a test case, all heights will be unique.
 

Output
For each test case , output “Case %d: “first where d is the case number counted from one, then output a single integer representing the maximum distance between the shortest and tallest house, subject to the constraints above, or -1 if it is impossible to lay out the houses. Do not print any blank lines between answers.
 

Sample Input
3 4 4 20 30 10 40 5 6 20 34 54 10 15 4 2 10 20 16 13
 

Sample Output
Case 1: 3 Case 2: 3 Case 3: -1

// Bellman_Ford 
#include <stdio.h>
#include 
<memory>
#include 
<iostream>
#include 
<algorithm>
#include 
<cstring>
#include 
<vector>
#include 
<map>
#include 
<cmath>
#include 
<set>
#include 
<queue>
#include 
<time.h> 
#include 
<limits>
using namespace std;
#define typev int
#define N 1005
#define inf 0x7fffffff 
#define E (N*5) 
const double pi = acos(-1.0); 
struct e{
    
int st, ed; 
    typev len;  
    
void set(int _st, int _ed, typev _len){
        st 
= _st; 
        ed 
= _ed; 
        len 
= _len; 
    }
}es[E];
struct node{
    
int h; 
    
int i; 
}nodes[N];
e
* fir[N]; 
int n, en, d;
int st, ed; 
int vis[N], t[N], que[N]; 
typev dist[N]; 
inline 
bool cmp(node n1, node n2){
    
return n1.h < n2.h; 
}
inline 
bool relax(int st, int ed, int len){
    
if(dist[st] < inf && dist[ed] > dist[st] + len){
        dist[ed] 
= dist[st] + len;
        
return true
    }
    
return false
}
bool Bellman_Ford(int n, int st){  //返回true表示有負環
    int i, j; 
    
bool flag; 
    
for(i = 0; i < n; i++) dist[i] = inf; 
    dist[st] 
= 0
    
for(i = 0; i < n; i++){
        flag 
= false
        
for(j = 0; j < en; j++){
            
if(relax(es[j].st, es[j].ed, es[j].len)) flag = true
        }
        
if(!flag) break
    }
    
return flag;  
}
int cnt = 0
int main(){
#ifndef ONLINE_JUDGE
    freopen(
"in.txt""r", stdin); 
    
//freopen("out.txt", "w", stdout); 
#endif 

    
int t, i, ans, u, v;
    scanf(
"%d"&t);
    
while(t--){
        scanf(
"%d%d"&n, &d);
        
for(i = 0; i < n; i++){
            scanf(
"%d"&nodes[i].h);
            nodes[i].i 
= i; 
        }
        en 
= st = ed = 0
        sort(nodes, nodes
+n, cmp); 
        st 
= nodes[0].i; 
        ed 
= nodes[n - 1].i; 
        
if(st > ed) swap(st, ed); 
        
for(i = 0; i < n; i++) fir[i] = NULL; 
        
for(i = 1; i < n; i++){
            es[en
++].set(i, i-1-1); 
            u 
= nodes[i].i; 
            v 
= nodes[i - 1].i; 
            
if(u < v){
                es[en
++].set(u, v, d); 
            }
else es[en++].set(v, u, d); 
        } 
        
if(!Bellman_Ford(n, st)) ans = dist[ed];
        
else ans = -1
        printf(
"Case %d: %d\n"++cnt, ans);

    }
    
return 0;
}



posted on 2011-01-23 01:13 tw 閱讀(506) 評論(0)  編輯 收藏 引用 所屬分類: HDU題解

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿

文章分類

文章檔案

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲精品在线观看视频| 国产欧美日韩亚洲精品| 亚洲国产精品国自产拍av秋霞| 香蕉av福利精品导航| 亚洲午夜视频在线| 欧美一二三区在线观看| 久久精品伊人| 欧美 日韩 国产一区二区在线视频| 久久久久久综合网天天| 老妇喷水一区二区三区| 亚洲高清资源| 亚洲婷婷在线| 久久国产精品毛片| 久久综合激情| 欧美日韩国产经典色站一区二区三区| 欧美日韩精品免费观看视频完整| 国产精品久久久久久久久久久久久久| 国产欧美综合在线| 亚洲精品人人| 久久精品国产一区二区三区免费看| 欧美r片在线| 中文亚洲免费| 麻豆国产精品一区二区三区| 欧美日本中文| 国内精品免费在线观看| 亚洲最新色图| 久久综合久久88| 亚洲午夜精品久久| 免费观看不卡av| 国产日本欧美一区二区| 一本色道久久综合亚洲精品高清 | 亚洲第一在线综合网站| 99国内精品| 久久午夜精品一区二区| 妖精成人www高清在线观看| 久久精品亚洲精品| 国产精品久久夜| 亚洲三级影片| 蜜臀a∨国产成人精品| 一区二区三区不卡视频在线观看| 欧美在线999| 欧美日韩在线第一页| 亚洲国产成人av好男人在线观看| 午夜日本精品| 正在播放欧美视频| 欧美日韩国产三区| 亚洲人成77777在线观看网| 久久九九全国免费精品观看| 在线视频你懂得一区| 欧美日本亚洲| 99日韩精品| 亚洲缚视频在线观看| 久久久久天天天天| 国产最新精品精品你懂的| 亚洲欧美怡红院| 亚洲第一久久影院| 99视频+国产日韩欧美| 亚洲欧洲午夜| 欧美a级片网站| 久久精品日产第一区二区三区| 国产精品久久久久天堂| 洋洋av久久久久久久一区| 欧美激情在线观看| 欧美成年视频| 亚洲精品国偷自产在线99热| 欧美成人午夜77777| 久久亚洲精品一区二区| 黄色成人av| 欧美99久久| 女仆av观看一区| 99精品久久久| 日韩视频一区二区在线观看| 欧美日韩亚洲免费| 亚洲欧洲av一区二区| 亚洲影视综合| 国产视频观看一区| 模特精品裸拍一区| 欧美韩日视频| 亚洲无吗在线| 欧美一区三区三区高中清蜜桃| 国产亚洲一区二区三区| 久久综合给合| 欧美激情国产精品| 亚洲一区二区三区精品在线| 亚洲欧美国产精品va在线观看| 韩国福利一区| 日韩视频精品在线| 国产精品一区二区三区免费观看| 香蕉视频成人在线观看 | 欧美激情精品久久久久久蜜臀| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲国产精品一区| 亚洲精品国产精品乱码不99| 国产精品高清免费在线观看| 欧美制服第一页| 欧美77777| 午夜老司机精品| 久久久久久亚洲精品杨幂换脸 | 一区二区三区www| 亚洲欧美视频一区| 亚洲国产日韩欧美综合久久| 一区二区不卡在线视频 午夜欧美不卡在 | 模特精品在线| 午夜精品理论片| 亚洲一区二区毛片| 亚洲一区美女视频在线观看免费| 亚洲精美视频| 国产精品久久久一区二区三区| 久久亚洲精品欧美| 欧美区二区三区| 久久久久在线| 欧美视频国产精品| 亚洲国产精品成人综合色在线婷婷| 国产欧美激情| 99国产精品久久| 悠悠资源网亚洲青| 亚洲欧美日韩精品久久久| 亚洲激情视频在线播放| 午夜在线不卡| 午夜一区二区三区不卡视频| 欧美国产1区2区| 欧美1级日本1级| 激情久久五月天| 亚洲欧美日韩综合国产aⅴ| 亚洲视频在线观看| 欧美美女日韩| 亚洲国产精品一区在线观看不卡| 黄色成人在线网址| 久久成人这里只有精品| 亚洲综合不卡| 国产精品捆绑调教| 一本到12不卡视频在线dvd| 伊人伊人伊人久久| 久久三级福利| 欧美成人午夜| 亚洲三级观看| 欧美国产日韩一区二区在线观看| 美日韩丰满少妇在线观看| 极品av少妇一区二区| 久久久免费精品视频| 免费中文字幕日韩欧美| 亚洲精品国产精品乱码不99| 欧美激情欧美狂野欧美精品 | 欧美岛国在线观看| 最新亚洲一区| 欧美日韩国产不卡| 在线一区二区三区四区五区| 亚洲在线网站| 国产精品一区免费观看| 亚洲欧美日韩在线观看a三区| 欧美一区二区三区在| 国产亚洲欧美激情| 欧美在线观看一二区| 男女视频一区二区| 亚洲日韩中文字幕在线播放| 欧美另类69精品久久久久9999| 亚洲精品乱码久久久久久黑人| 亚洲性人人天天夜夜摸| 国产麻豆91精品| 久久久久久久久久久久久9999| 免费观看成人| 一区二区三区你懂的| 国产欧美三级| 久久精视频免费在线久久完整在线看| 久色婷婷小香蕉久久| 9久草视频在线视频精品| 国产精品国产精品| 久久精品视频99| 日韩午夜中文字幕| 久久精品国产欧美激情| 亚洲啪啪91| 国产精品日韩欧美大师| 国内精品视频在线观看| 嫩草影视亚洲| 日韩手机在线导航| 国产精品一区免费观看| 狼人社综合社区| 一区二区三区久久久| 久久蜜桃资源一区二区老牛| 99精品国产在热久久婷婷| 国产精品私拍pans大尺度在线 | 欧美午夜精品一区| 欧美在线观看一区| 亚洲日本va在线观看| 久久久青草婷婷精品综合日韩 | 久久综合影视| 正在播放亚洲| 亚洲第一页中文字幕| 国产精品久久久久久一区二区三区| 久久精品国产2020观看福利| 日韩视频在线你懂得| 免费视频亚洲| 亚洲欧美综合国产精品一区| 亚洲人成人一区二区三区| 国产亚洲毛片在线| 国产精品国产成人国产三级| 欧美成人午夜视频| 久久精品亚洲一区| 亚洲一区视频| 一区二区三区四区五区在线|