zoukankan      html  css  js  c++  java
  • poj 1088 滑雪

    题目链接:http://poj.org/problem?id=1088

    解题思路:贪心+简单dp

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: poj 1088
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 typedef long long LL;
    26 const double PI=acos(-1.0);
    27 
    28 const int x4[]={-1,0,1,0};
    29 const int y4[]={0,1,0,-1};
    30 const int x8[]={-1,-1,0,1,1,1,0,-1};
    31 const int y8[]={0,1,1,1,0,-1,-1,-1};
    32 
    33 typedef int T;
    34 T max(T a,T b){ return a>b? a:b; }
    35 T min(T a,T b){ return a<b? a:b; }
    36 ///////////////////////////////////////////////////////////////////////////
    37 
    38 ///////////////////////////////////////////////////////////////////////////
    39 //Add Code:
    40 struct Node{
    41     int i,j,h;
    42     bool operator <(const Node &a) const{
    43         return h<a.h;
    44     }
    45 }t[10005];
    46 ///////////////////////////////////////////////////////////////////////////
    47 
    48 int main(){
    49     ///////////////////////////////////////////////////////////////////////
    50     //Add code:
    51     int R,C,i,j,a[105][105],dp[105][105];
    52     scanf("%d%d",&R,&C);
    53     for(i=0;i<=R+1;i++){
    54         for(j=0;j<=C+1;j++){
    55             a[i][j]=10005;
    56             dp[i][j]=1;
    57         }
    58     }
    59     int num=0;
    60     for(i=1;i<=R;i++){
    61         for(j=1;j<=C;j++){
    62             scanf("%d",&a[i][j]);
    63             t[num++]=Node{i,j,a[i][j]};
    64         }
    65     }
    66     sort(t,t+num);
    67     int Max=0;
    68     for(int k=0;k<num;k++){
    69         i=t[k].i,j=t[k].j;
    70         for(int p=0;p<4;p++){
    71             int u=i+x4[p],v=j+y4[p];
    72             if(a[u][v]<a[i][j] && dp[u][v]+1>dp[i][j]) dp[i][j]=dp[u][v]+1;
    73         }
    74         Max=max(Max,dp[i][j]);
    75     }
    76     printf("%d
    ",Max);
    77     ///////////////////////////////////////////////////////////////////////
    78     return 0;
    79 }
    80 
    81 ///////////////////////////////////////////////////////////////////////////
    82 /*
    83 Testcase:
    84 Input:
    85 5 5
    86 1 2 3 4 5
    87 16 17 18 19 6
    88 15 24 25 20 7
    89 14 23 22 21 8
    90 13 12 11 10 9
    91 Output:
    92 25
    93 */
    94 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    TextView 字数限制
    关于一个软件ipa包的其他图片资源
    查看一个软件ipa包的内容
    不断学习的博客
    高级iOS面试题
    CocoaPod出现-bash: pod: command not found 解决办法
    链表清空
    蛋疼的并查集
    再卖菜
    乒乓球男双输了
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3279112.html
Copyright © 2011-2022 走看看