zoukankan      html  css  js  c++  java
  • Association for the Country of Mububa Kattis

    题目链接:

    https://cn.vjudge.net/problem/Kattis-mububa

    题目大意:

    给你n个箱子,每个箱子里面装着一定数量的香蕉,让你按照这个箱子的顺序分发这些香蕉;在每个人获得的香蕉是非递减的前提下,最多能分多少个人?

    具体思路:

    dp[i]表示以第i个为结尾的这个人拿多少的香蕉是最合适的。

    num数组记录人数。

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 # define inf 0x3f3f3f3f
     4 # define ll_inf (1ll<<60)
     5 # define ll long long
     6 # define lson l,mid,rt<<1
     7 # define rson mid+1,r,rt<<1|1
     8 const ll maxn = 3e5+100;
     9 const ll mod = 1e9+7;
    10 ll dp[maxn];
    11 ll pre[maxn];
    12 ll num[maxn];
    13 int main()
    14 {
    15     int n;
    16     scanf("%d",&n);
    17     ll tmp;
    18     for(int i=1; i<=n; i++)
    19     {
    20         scanf("%lld",&tmp);
    21         pre[i]=pre[i-1]+tmp;
    22     }
    23     for(int i=1; i<=n; i++)
    24     {
    25         for(int j=i-1; j>=0; j--)
    26         {
    27             if(pre[i]-pre[j]>=dp[j])//  这里找到之后停了就可以了;假设最优解在前面,那么这个点的后面也一定能符合的,因为是越加越多的
    28             {
    29                 dp[i]=pre[i]-pre[j];
    30                 num[i]=num[j]+1;
    31                 break;
    32             }
    33         }
    34     }
    35     printf("%lld
    ",num[n]);
    36     return 0;
    37 }
  • 相关阅读:
    flyway
    xxl-job
    响应式布局
    position: fixed
    position: absolute
    position: relative
    GDB高级一点的命令
    坑爹的大页内存
    input8按键对照
    discuz插件应用原理分析
  • 原文地址:https://www.cnblogs.com/letlifestop/p/11002174.html
Copyright © 2011-2022 走看看