vj原题链接:G - Association for the Country of Mububa
You are the boss of ACM (Association for the Country of Mububa), an upstanding company with a single goal of world domination.
Today, you have conquered the unnamed country of Mububa (how an unnamed country has a name is, of course, outside the scope of this problem). Mububa is known for its great, great, bananas. In light of this monumental achievement, you have decided to reward your executives with Mububa’s greatest treasure (which is obviously, bananas). You have prepared NN briefcases, each contains a number of bananas. These briefcases are numbered from 11 through NN.
You reward your executives one by one in order from the least evil executive, to the most evil executive (still not comparably evil to you, of course). No two executives are equally evil. For each executive, you first decide how many briefcases you want to give him. If you decide to give an executive aa briefcases, you give him the aa briefcases with lowest numbers that you still have. Each executive you reward must receive at least one briefcase.
It is important to be fair when distributing rewards. You do not want your executives to stage a hunger strike, after all. Thus, the rewards the executives received must reflect how evil they are. More rigorously, if executive AA is more evil than executive BB, then the total number of bananas received by executive AA must be at least as large as the total number of bananas received by executive BB.
You know the number of bananas inside all of the briefcases. You want to reward as many executives as possible, but wants the distribution to still be fair (i.e. following the previous requirement) amongst them. What is the maximum number of executives you can reward this way?
Input
The first line contains a non-negative integer 2 \leq N \leq 3\, 0002≤N≤3000, giving the number of briefcases you have. Then follows a line with NN integers, the ii-th of which denotes the number of bananas in briefcase number ii. Each briefcase contains between 11 and 10^9109 bananas, inclusively.
Output
Print the maximum number of executives you can reward with bananas.
Sample Data explanation
In the first example, give briefcase 11 to the least evil executive, briefcase 22 to the second least evil executive, and briefcases 33 and 44 to the most evil executive.
In the second example, give briefcase 11 to the least evil executive, briefcases 22 and 33 to the second least evil executive, and briefcases 44, 55, and 66 to the most evil executive.
Sample 1
Inputcopy | Outputcopy |
---|---|
4 1 2 1 2 | 3 |
Sample 2
Inputcopy | Outputcopy |
---|---|
6 6 4 2 2 2 2 | 3 |
题意:给n个数字要形成尽可能多的区间使得区间和呈非严格递增的排列问有最多多少个这种区间
思路分析:dp问题模型有点类似于最长上升子序列模型但是包装的比较好(个人认为)区间和明显用前缀和来表示。区间尽可能多——>贪心(让最后一个区间和尽可能的小)
状态表示;f[N] f[i]表示前i个数最多能形成多少区间(注意这里题目说明每个数都会参与形成区间)
状态计算:f[i]=f[j]+1; j 表示形成的最后一个区间的前一个区间右端点 同时开另外一个数组来存一下以j结尾的最后一个区间和
一定不要开long long
#include <math.h>
#include<map>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define PI acos(-1)
#include <string.h>
using namespace std;
const int N = 1e6 + 5, M = 1e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
const double esp = 1e-6;
typedef pair<int, int> PII;
int a[N];
int n;
long long su[N];
int f[N];
long long best[N];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
su[i]=su[i-1]+a[i];
}
for(int i=1;i<=n;i++)
{
for(int j=i;j>=1;j--)
{
if(su[i]-su[j-1]>=best[j-1])
{
f[i]=f[j-1]+1;
best[i]=su[i]-su[j-1];
break;
}
}
}
printf("%d\n",f[n]);
return 0;
}