zoukankan      html  css  js  c++  java
  • P1108-低价购买

     1 #include <bits/stdc++.h>
     2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     3 typedef long long ll;
     4 using namespace std;
     5 inline ll read()
     6 {
     7     ll ans = 0;
     8     char ch = getchar(), last = ' ';
     9     while(!isdigit(ch)) last = ch, ch = getchar();
    10     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    11     if(last == '-') ans = -ans;
    12     return ans;
    13 }
    14 inline void write(ll x)
    15 {
    16     if(x < 0) x = -x, putchar('-');
    17     if(x >= 10) write(x / 10);
    18     putchar(x % 10 + '0');
    19 }
    20 int N;
    21 ll a[5003];
    22 ll dpt[5003];
    23 ll dptend = 0;
    24 ll dp1[5003];
    25 ll dp2[5003];
    26 ll rnt1 = 1,rnt2;
    27 int main()
    28 {
    29     N = read();
    30     _for(i,1,N+1)
    31     a[i] = read();
    32 
    33     dpt[++dptend] = a[1];
    34     dp1[1] = 1;
    35     _for(i,2,N+1)
    36     {
    37         if(a[i] < dpt[dptend])
    38         {
    39             dpt[++dptend] = a[i];
    40             dp1[i] = dptend;
    41         }
    42         else
    43         {
    44             int t = lower_bound(dpt+1,dpt+1+dptend,a[i],greater<int>())-dpt;
    45             dpt[t] = a[i];
    46             dp1[i] = t;
    47         }
    48         rnt1 = max(rnt1,dptend);
    49     }
    50     
    51     _for(i,1,N+1)
    52     {
    53         if(dp1[i]==1) 
    54             dp2[i] = 1;
    55         _for(j,1,i)
    56         {
    57             if(dp1[i]==dp1[j]+1 && a[i]<a[j])
    58                 dp2[i] += dp2[j];
    59             else if(dp1[i] == dp1[j] && a[i]==a[j])
    60                 dp2[i] = 0;
    61         }
    62         if(dp1[i]==rnt1)
    63             rnt2 += dp2[i];
    64     }
    65     printf("%lld %lld
    ",rnt1,rnt2);
    66     return 0;
    67 }
  • 相关阅读:
    使用GitHub+hexo搭建个人独立博客
    HDU 3038
    POJ 1417
    HDU 1213
    ZOJ 3781
    ZOJ 3780
    ZOJ 3777
    HDU 3045
    HDU 3480
    POJ 1180
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11371578.html
Copyright © 2011-2022 走看看