zoukankan      html  css  js  c++  java
  • HDU 1160 FatMouse's Speed

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1160

    解题思路:

    这也是一道最长单调递增子序列问题。

    主要注意是:

    这些数据可以排序。

    输出路径时,打印的原来输入的编号。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <iostream>
     5 using namespace std;
     6 
     7 const int MAXN=10000;
     8 const int INF=1<<20;
     9 
    10 struct node{
    11     int w,s;
    12     int n;
    13     bool operator <(const node &rhs) const{
    14         if(w!=rhs.w)
    15             return w<rhs.w;
    16         else
    17             return s>rhs.s;
    18     }
    19 }Mou[MAXN];
    20 
    21 int dp[MAXN];
    22 int pre[MAXN];
    23 
    24 void output(int k){
    25    if(pre[k]==-1){
    26     printf("%d
    ",Mou[k].n);
    27     return;
    28    }
    29    output(pre[k]);
    30    printf("%d
    ",Mou[k].n);
    31 }
    32 
    33 
    34 
    35 int main(){
    36     int cnt=0;
    37     while(scanf("%d%d",&Mou[cnt].w,&Mou[cnt].s)!=EOF){
    38         Mou[cnt].n=cnt+1;  //注意下标是从1开始的,刚刚没有注意到,然后一直在在这儿wrong
    39         cnt++;
    40     }
    41 
    42 
    43     int Mlg=-INF;
    44     int last=-1;
    45     memset(dp,0,sizeof(dp));
    46     memset(pre,-1,sizeof(pre));
    47 
    48     sort(Mou,Mou+cnt);
    49     for(int i=0;i<cnt;i++){
    50         dp[i]=1;
    51         for(int j=0;j<i;j++){
    52             if(Mou[i].w>Mou[j].w&&Mou[i].s<Mou[j].s){
    53                 if(dp[i]<dp[j]+1){
    54                     dp[i]=dp[j]+1;
    55                     pre[i]=j;
    56                 }
    57             }
    58         }
    59         if(Mlg<dp[i]){
    60             Mlg=dp[i];
    61             last=i;
    62         }
    63     }
    64     cout<<Mlg<<endl;
    65     output(last);
    66     return 0;
    67 }
    自己选的路,跪着也要把它走完------ACM坑
  • 相关阅读:
    LAMP 环境搭建备忘 -- Linux的安装(一)
    Qt 的一些浅知识点
    chm 转 txt
    SQL 语句 (二) --- SELECT
    SQL语句 (一)
    量子电路
    量子隐形传态 Quantum Teleportation
    量子逻辑门
    量子纠缠2——CHSH不等式
    量子纠缠1——量子比特、Bell态、EPR佯谬
  • 原文地址:https://www.cnblogs.com/IKnowYou0/p/6606549.html
Copyright © 2011-2022 走看看