zoukankan      html  css  js  c++  java
  • usaco 2000 contest 滑雪

    2013-09-11 10:22

    【题目大意】给定N个点的高度和M条相连的路线(单向),从最高点向下走,

    到无法走时为一条路径,求不同的路径数,(一节点不同就叫不同)

    【输入样例】

    4 5   (N,M)

    500 400 300 200  (高度)

    1 2                (边)

    2 3

    3 4

    1 4

    2 4

    【输出样例】

    3

    //By BLADEVIL
    var
        n, m                    :longint;
        pre, other              :array[0..5100] of longint;
        last                    :array[0..300] of longint;
        h                       :array[0..300] of longint;
        max                     :longint;
        vis                     :array[0..300] of boolean;
        l                       :longint;
        ans                     :longint;
    
    procedure connect(x,y:longint);
    begin
        inc(l);
        pre[l]:=last[x];
        last[x]:=l;
        other[l]:=y;
    end;
    
    procedure init;
    var
        i, x, y, z              :longint;
    begin
    assign(input,'ski.in'); reset(input);
    assign(output,'ski.out'); rewrite(output);
        read(n,m);
        max:=0; l:=1;
        for i:=1 to n do
        begin
            read(h[i]);
            if h[i]>h[max] then max:=i;
        end;
        for i:=1 to m do
        begin
            read(x,y);
            connect(x,y);
        end;
    end;
    
    procedure dfs(x:longint);
    var
        p, q                    :longint;
    begin
        q:=last[x];
        if q=0 then
        begin
            inc(ans);
            exit;
        end;
        while q<>0 do
        begin
            p:=other[q];
            if not vis[p] then
            begin
                vis[p]:=true;
                dfs(p);
                vis[p]:=false;
            end;
            q:=pre[q];
        end;
    
    end;
    
    
    begin
        init;
        dfs(max);
        writeln(ans);
    close(input); close(output);
    end.
  • 相关阅读:
    Python之实现一个优先级队列
    java可变参数列表的实现
    static 关键字详解 static方法调用非static属性和方法
    this关键字详解
    vue自定义事件 子组件把数据传出去
    vue组件 Prop传递数据
    Vue 什么是组件
    vue v-model 表单控件绑定
    vue v-on监听事件
    vue v-if with v-for
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3433493.html
Copyright © 2011-2022 走看看