题意:

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 poll

    man poll: NAME poll, ppoll - wait for some event on a file descriptor SYNOPSIS #include <poll.h&g ...

  2. PHP高级特性一之正则表达式用法

    在PHP中,我们进行字符串处理时,能用字符串处理函数时我们当然要使用简单的字符串处理函数,但字符串处理函数的能力是有限的,所以我们就需要利用一个更强大的工具,那就是正则表达式. 简述正则表达式 正则表 ...

  3. HDU 1054:Strategic Game

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. Android Touch(1)事件的传递流程(*)

    1,Activity,ViewGroup,View的关系 2,触摸事件 3,传递事件时的重要函数 4,事件传递流程参考图 5,其它参考资料 1,Activity,ViewGroup,View的关系 本 ...

  5. php关于return的关键字

    使用return关键字可以使函数返回值,可以返回包括数组和对象的任意类型,如果省略了 return,则默认返回值为 NULL. function add($a) { return $a+1; } $b ...

  6. find-right-interval

    https://leetcode.com/problems/find-right-interval/ Java里面TreeMap或者TreeSet有类似C++的lower_bound或者upper_b ...

  7. jQuery_效果(滑动)

    1.jQuery slideDown() 方法(用于向下滑动元素) 语法:$(selector).slideDown(speed,callback); 可选的 speed 参数规定效果的时长.它可以取 ...

  8. Qt Linguist介绍

    简介 Qt提供了一款优秀的支持Qt C++和Qt Quick应用程序的翻译工具.发布者.翻译者和开发者可以使用这款工具来完成他们的任务. 发布者:承担了全面发布应用程序的责任.通常,他们协调开发者和翻 ...

  9. Qt环境搭建(Visual Studio)

    简述 经常有人问我编写Qt程序时使用什么IDE,其实这个真的很难回答(各有所长),只能说看个人爱好了,因为我两个都用,而且两个都很喜欢(比较多情吧O(∩_∩)O~)! 下面将进行Qt Creator与 ...

  10. xxx_cast类型转换

    xxx_cast是一个统称,它指的是static_cast(静态转换),const_cast(常量转换),reinterpert_cast(重解释转换),dynamic_cast(动态转换).本次我们 ...