P1108-低价购买

r囧r小猫 2023-06-01 08:52 108阅读 0赞
  1. 1 #include <bits/stdc++.h>
  2. 2 #define _for(i,a,b) for(int i = (a);i < b;i ++)
  3. 3 typedef long long ll;
  4. 4 using namespace std;
  5. 5 inline ll read()
  6. 6 {
  7. 7 ll ans = 0;
  8. 8 char ch = getchar(), last = ' ';
  9. 9 while(!isdigit(ch)) last = ch, ch = getchar();
  10. 10 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  11. 11 if(last == '-') ans = -ans;
  12. 12 return ans;
  13. 13 }
  14. 14 inline void write(ll x)
  15. 15 {
  16. 16 if(x < 0) x = -x, putchar('-');
  17. 17 if(x >= 10) write(x / 10);
  18. 18 putchar(x % 10 + '0');
  19. 19 }
  20. 20 int N;
  21. 21 ll a[5003];
  22. 22 ll dpt[5003];
  23. 23 ll dptend = 0;
  24. 24 ll dp1[5003];
  25. 25 ll dp2[5003];
  26. 26 ll rnt1 = 1,rnt2;
  27. 27 int main()
  28. 28 {
  29. 29 N = read();
  30. 30 _for(i,1,N+1)
  31. 31 a[i] = read();
  32. 32
  33. 33 dpt[++dptend] = a[1];
  34. 34 dp1[1] = 1;
  35. 35 _for(i,2,N+1)
  36. 36 {
  37. 37 if(a[i] < dpt[dptend])
  38. 38 {
  39. 39 dpt[++dptend] = a[i];
  40. 40 dp1[i] = dptend;
  41. 41 }
  42. 42 else
  43. 43 {
  44. 44 int t = lower_bound(dpt+1,dpt+1+dptend,a[i],greater<int>())-dpt;
  45. 45 dpt[t] = a[i];
  46. 46 dp1[i] = t;
  47. 47 }
  48. 48 rnt1 = max(rnt1,dptend);
  49. 49 }
  50. 50
  51. 51 _for(i,1,N+1)
  52. 52 {
  53. 53 if(dp1[i]==1)
  54. 54 dp2[i] = 1;
  55. 55 _for(j,1,i)
  56. 56 {
  57. 57 if(dp1[i]==dp1[j]+1 && a[i]<a[j])
  58. 58 dp2[i] += dp2[j];
  59. 59 else if(dp1[i] == dp1[j] && a[i]==a[j])
  60. 60 dp2[i] = 0;
  61. 61 }
  62. 62 if(dp1[i]==rnt1)
  63. 63 rnt2 += dp2[i];
  64. 64 }
  65. 65 printf("%lld %lld\n",rnt1,rnt2);
  66. 66 return 0;
  67. 67 }

转载于:https://www.cnblogs.com/Asurudo/p/11371578.html

发表评论

表情:
评论列表 (有 0 条评论,108人围观)

还没有评论,来说两句吧...

相关阅读

    相关 1108 String复读机(JAVA)

    给定一个长度不超过 104 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 `StringString....` (注意区分大小写)这样的顺序输出,并忽略其它字符。当然