题意:

n个数分成m段,每段偶数个数,最小化和最大段的半个区间的数字和。

分析:

先想到了二分,dp求能分成的最小段数。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int dp[][],sum[],n,m,d;
int judge(int x){
dp[][]=;
dp[][]=INF;
for(int i=;i<=n;++i){
dp[i][]=dp[i][]=INF;
for(int l=;l<=d&&(i-*l)>=;++l){
if(sum[i]-sum[i-l]>x)break;
if(sum[i-l]-sum[i-*l]<=x){
dp[i][]=min(dp[i][],dp[i-*l][]+);
dp[i][]=min(dp[i][],dp[i-*l][]+);
}
}
}
return dp[n][(m-)%]>m-;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&d);
int a;
sum[]=;
for(int i=;i<=n;++i)
{
scanf("%d",&a);
sum[i]=sum[i-]+a;
}
if(n%||n<*(m-)||n>*d*(m-))
{
printf("BAD\n");continue;
}
int l=,r=sum[n];
while(l<=r){
int mid=(l+r)>>;
if(judge(mid))l=mid+;
else r=mid-;
}
printf("%d\n",l);
}
return ;
}

Garlands的更多相关文章

  1. Codeforces 707E Garlands

    Garlands 我怎么感觉好水啊. 因为询问只有2000组, 离线询问, 枚举联通块再枚举询问, 二维树状数组更新答案. #include<bits/stdc++.h> #define ...

  2. Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力

    E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...

  3. Three Garlands~Educational Codeforces Round 35

    C. Three Garlands time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces 707 E. Garlands (二维树状数组)

    题目链接:http://codeforces.com/problemset/problem/707/E 给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值. 有q个操作,操作ask问 ...

  5. CF368 E - Garlands

    主席树 其实暴力二维树状还更快 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int M ...

  6. Garlands CodeForces - 707E (离线树状数组)

    大意: 给定n*m矩阵, k条链, 链上每个点有权值, 每次操作可以关闭或打开一条链或询问一个子矩阵内未关闭的权值和. 关键询问操作比较少, 可以枚举每条链, 暴力算出该条链对每个询问的贡献. 最后再 ...

  7. [CF911C]Three Garlands

    题目大意: 给你三个灯,分别以k1秒一次,k2秒一次和k3秒一次的频率闪烁着. 你可以自定义三个灯开启的时间,问是否有一种方案,使得max(k1,k2,k3)秒之后,每秒钟都至少有一盏灯闪烁. 思路: ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. CF #368 div2

    题目链接:http://codeforces.com/contest/707/problem/A A. Brain's Photos time limit per test 2 seconds mem ...

随机推荐

  1. linux 安装scons

     scons是一个Python写的自动化构建工具,需要安装python和scons后才能运行,能够跨平台.其集成功能类似于autoconf/automake ,是一个简洁可靠的工具.现在很多系统都自带 ...

  2. Data Flow ->> Merge

    Merge组件的作用和Union All很相似,就是把两个输入源的结果集合并成一个.但是不同之处在于: 1)Merge输入的结果集需要先经过排序(这点表示怀疑) 2)Merge对于输入的两个结果集的数 ...

  3. Matlab绘图高级部分

    图形是呈现数据的一种直观方式,在用Matlab进行数据处理和计算后,我们一般都会以图形的形式将结果呈现出来.尤其在论文的撰写中,优雅的图形无疑会为文章加分.本篇文章非完全原创,我的工作就是把见到的Ma ...

  4. Case 架构的实际应用-1

    We use testlink to manage cases, and the frame is below: Project Name -All Features(Modules) -Featur ...

  5. iPhone 已停用

    如果你的iPhone上出现了如下的显示,你可以参考苹果官网上的  iOS设备已停用 如果你看到了这篇文章,你比我幸运多了. 参考这一个条目,你也许就不会丢失里面的数据了. 可怜的我,出现这个问题时还没 ...

  6. BZOJ 1502 月下柠檬树(simpson积分)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1502 题意:给出如下一棵分层的树,给出每层的高度和每个面的半径.光线是平行的,与地面夹角 ...

  7. webhdfs追加写HDFS异常

    问题 {:timestamp=>"2015-03-04T00:02:47.224000+0800", :message=>"Retrying webhdfs ...

  8. 编写类String的构造函数、析构函数和赋值函数

    已知类String的原型为: class String {   public:  String(const char *str = NULL); // 普通构造函数  String(const Str ...

  9. hdu1051(LIS | Dilworth定理)

    这题根据的Dilworth定理,链的最小个数=反链的最大长度 , 然后就是排序LIS了 链-反链-Dilworth定理 hdu1051 #include <iostream> #inclu ...

  10. HDU 1850 (Nim博弈 取胜方案数) Being a Good Boy in Spring Festival

    考虑到Bouton定理的证明过程,设n个数的Nim和(异或和)为X,其最高位的1在第k位,那么n个数中一定有个y的第k为也是个1. 将y的数量变为X xor y,那么n的数的Nim和为0,便转为先手必 ...