列表

详情


NC214901. Fountains

描述

Suppose you and your teammate Mixsx will attend the Namomo Camp. The Namomo Camp will happen in consecutive days. We name the -th day as day (). The cost of day is s_i.

Unfortunately, the schedule of the Namomo Camp conflicts with Mixsx's final exams. Mixsx has final exams every day between day and day . The exact value of and have not been announced by his college so we assume that every pair of integers and satisfying will be chosen with probability . He decides to take all the exams and thus be absent from the Namomo Camp from day to day . His loss will be in this case.  

As Mixsx's teammate, you want Mixsx to give up his final exams and come back to the Namomo Camp. You can prepare plans before and are announced. In the -th plan (), you shut the electricity off to his college every day from day l_i to day r_i. You can choose the values of l_i and r_i as long as they are two integers satisfying .

Once and are announced, you can choose a plan () such that . Then Mixsx will come back to the Namomo Camp on every day from day l_x to day r_x. His loss becomes in this case. You will choose a plan that minimizes Mixsx's loss. If no plan satisfies , Mixsx will attend his final exams normally and his loss is .

Please calculate the minimum possible expected loss ans_k of Mixsx if you choose the plans optimally. Output for every from 1 to .

Formally, given a list of numbers , define a loss function . Given an integer (), you should select integers satisfying for all , such that



is minimized. ( is defined as 0 if no satisfies and .) Output the minimized value for every integer in .

输入描述

The first line contains an integer . The second line contains  space separated integers .

输出描述

The output contains  integers in their own lines, the expectations when  multiplied by . It can be shown that the results are always integers.

示例1

输入:

1
1

输出:

0

说明:

For the first test case, we only need to consider the case {k = 1}. We can only choose l_1=r_1=1. Then the expected loss is {C(1, 1) - C(1, 1) = 0} and the result is 0 \times 1 \times (2) / 2 = 0.

示例2

输入:

2
13 24

输出:

26
13
0

示例3

输入:

3
6 4 7

输出:

33
21
12
8
4
0

说明:

For the third test case, consider the case when {k = 3}. We choose l_1=r_1=1, l_2=r_2=3 and l_3=1, r_3=3. The expected loss is 2. And the result is 2 \times 6 = 12.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 1579ms, 内存消耗: 101624K, 提交时间: 2021-02-07 09:45:45

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,num;
ll sum,s[11],ans[89];
struct P{ll v;int l,r;}a[89];
map<vector<int>,ll>cur,pre;
vector<int>b;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%lld",&s[i]),s[i]+=s[i-1];
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j){
			a[++num]=P{s[j]-s[i-1],i,j};
			sum+=s[j]-s[i-1];
		}		
	sort(a+1,a+num+1,[&](P x1,P x2){return x1.v>x2.v;});
	for(int i=0;i<n;++i)b.pb(n);b.pb(0);
	cur[b]=0;
	for(int x=1;x<=num;++x){
		int l=a[x].l,r=a[x].r;ll v=a[x].v; 
		pre=cur;
		for(auto o:pre){
			auto b=o.first;ll nv=o.second;
			for(int i=0;i<l;++i){
				if(b[i]>=r)nv+=(b[i]-r+1)*v,b[i]=r-1;
			}
			b[n]++;
			cur[b]=max(cur[b],nv);
			ans[b[n]]=max(ans[b[n]],nv);
		}
	}
	for(int i=1;i<=(n+1)*n/2;++i)printf("%lld\n",sum-ans[i]);
	return 0;
}

上一题