Codeforces Round #493 (Div. 2) B. Cutting 前缀和优化_动归水题
不解释,题目过水
Code:
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 1000 + 3;
int A[maxn], n, odds[maxn], f[200][200],b;
int main()
{
scanf("%d%d",&n,&b);
for(int i = 1;i <= n; ++i)
{
scanf("%d",&A[i]);
if(A[i] % 2 == 1) odds[i] = 1;
odds[i] += odds[i - 1];
}
for(int i = 1;i <= n; ++i)
{
for(int k = 0;k <= b; ++k)
{
for(int j = 1;j < i; ++j)
{
int delta = abs(A[j] - A[j + 1]);
if((odds[i] - odds[j]) * 2 != i - j) continue;
if(k - delta >= 0) f[i][k] = max(f[i][k], f[j][k - delta] + 1);
}
}
}
printf("%d",f[n][b]);
return 0;
}
Codeforces Round #493 (Div. 2) B. Cutting 前缀和优化_动归水题的更多相关文章
- Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...
- Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)
Problem Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- Cutting Codeforces Round #493 (Div. 2)
Cutting There are a lot of things which could be cut — trees, paper, “the rope”. In this problem you ...
- 【Codeforces Round #493 (Div. 2) B】Cutting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有在前i个位置奇数偶数出现次数都相同的地方才能切. (且不管前面怎么切,这里都能切的. 那么就相当于有n个物品,每个物品的代价 ...
- Codeforces Round #493 (Div 2) (A~E)
目录 Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars(容斥 计数) C ...
- Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】
任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...
- CodeForces Round #521 (Div.3) D. Cutting Out
http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...
- Codeforces Round #493 (Div. 2)
C - Convert to Ones 给你一个01串 x是反转任意子串的代价 y是将子串全部取相反的代价 问全部变成1的最小代价 两种可能 一种把1全部放到一边 然后把剩下的0变成1 要么把所有的 ...
随机推荐
- MyBatis源码分析(各组件关系+底层原理
MyBatis源码分析MyBatis流程图 下面将结合代码具体分析. MyBatis具体代码分析 SqlSessionFactoryBuilder根据XML文件流,或者Configuration类实例 ...
- 洛谷P3275 [SCOI2011]糖果_差分约束_判负环
Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; co ...
- 素数(Prime)
素数的判断: #include<math.h> bool IsPrime(int n) { ) return false; int sqr = (int)sqrt(1.0*n); ; i& ...
- 数据结构(1) 第一天 算法时间复杂度、线性表介绍、动态数组搭建(仿Vector)、单向链表搭建、企业链表思路
01 数据结构基本概念_大O表示法 无论n是多少都执行三个具体步骤 执行了12步 O(12)=>O(1) O(n) log 2 N = log c N / log c N (相当于两个对数进行了 ...
- 【JavaScript框架封装】使用Prototype给Array,String,Function对象的方法扩充
/* * @Author: 我爱科技论坛* @Time: 20180705 * @Desc: 实现一个类似于JQuery功能的框架* V 1.0: 实现了基础框架.事件框架.CSS框架.属性框架.内容 ...
- IOS与h5交互记录
博主之前做过移动端app嵌入网页,与Android和IOS有交互,一直没有时间分享过程.这里不多说Android交互啦-很简单,详细了解IOS与h5的交互吧. IOS不同语法和h5的交互所建立的JSB ...
- [CodeForces]986A Fair
大意:给一张图,每个图上有一个数,问以每个点为源点,经过的点包含k种数字的最小距离. 显然跑最短路会T,但我们注意到边权一定.某次学校考试就是类似题,可以bfs做,复杂度O(n),每种货物做一次,复杂 ...
- C#基础--索引器
classProgram { staticvoidMain(string[] args) { man mm =new man(); mm[0]="jingya"; mm[1]=&q ...
- 洛谷—— P1126 机器人搬重物
https://www.luogu.org/problem/show?pid=1126 题目描述 机器人移动学会(RMI)现在正尝试用机器人搬运物品.机器人的形状是一个直径1.6米的球.在试验阶段,机 ...
- 定时器SDK
定时器是一切SDK的根本,欲写SDK必先确定定时器,定时器效率的高低决定着SDK函数的效率,下面是我个人写的Linux C++服务器端进程SDK中的定时器,部分参照了ACE和RocketMQ定时器的思 ...