题目链接:https://codeforces.com/contest/1119/problem/E

题意:有n种长度的棍子,有a_i根2^i长度的棍子,问最多可以组成多少个三角形

题解:dp[i]表示前 i 种棍子可以组成的最大三角形数量,f[i]表示没有用到的棍子数量,三角形的形状只有两种(2 ^ i, 2 ^ i, 2 ^ i)或者(2 ^ i, 2 ^ i, 2 ^ j),显然先用之前剩下的来组三角形最优,然后就可以转移了。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 3e5 + ;
const int maxm = 1e6 + ;
const ll mod = ; int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int n;
cin >> n;
ll res = , ans = ;
for(int i = ; i < n; i++) {
ll a;
cin >> a;
ll mn = min(res, a / );
res -= mn, a -= * mn;
ans += mn + a / ;
a %= ;
res += a;
}
cout << ans << endl;
return ;
}

Codeforces Global Round 2 E. Pavel and Triangles(思维+DP)的更多相关文章

  1. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  2. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  3. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  4. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  7. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  8. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  9. Codeforces Global Round 2 Solution

    这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 D-> Div.1 E-> ...

随机推荐

  1. ding

    Import "shanhai.lua"Dim currHour,currMinute,currSecondDim mmRnd = 0Dim sumFor=Int(ReadUICo ...

  2. 过滤器( filter )的使用

    转自:https://www.jianshu.com/p/2ea2b0e4d1f2 过滤器通常 在 web 服务端用的比较多,有要功能 在客户端的请求访问后端资源之前,拦截这些请求. 在服务器的响应发 ...

  3. laravel框架视图中常用的逻辑结构forlese,foreach,ifelse等

    if 和else @if($name === 1) 这个数字是1 @else 这个数字非1 @endif switch @switch($name) @case(1) 变量name == 1 @bre ...

  4. k8s开发实践

    代码自动生成:https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/ 自定义controlle ...

  5. 机器学习-EM算法笔记

    EM算法也称期望最大化(Expectation-Maximum,简称EM)算法,它是一个基础算法,是很多机器学习领域算法的基础,比如隐式马尔科夫算法(HMM), LDA主题模型的变分推断,混合高斯模型 ...

  6. 关于#define 的宏替换的一些问题

    #define PI 3.14; int main() { , s = ; s = r * r * PI; s = PI * r * r; // s = 3.14; * r * r; printf(& ...

  7. truncate删除一个分区,测试全局索引是否失效

    目的,有一个清理数据的需求,需要删除历史的一个分区所有记录信息,但是存在主键global索引,如何更好的维护. 如下测试流程一 提前创建好一个已时间created 字段作为分区键的范围分区表 SQL& ...

  8. php 判断请求是否是json

    $object =file_get_contents("php://input"); $arr = is_json($object); if($arr){ var_dump($ar ...

  9. C# ObservableCollection两个字段排序的情况

    相对于System.Linq的OrderBy及OrderByDescending方法,调用后产生IOrderedEnumberable对象,这个对象为排序后的返回值,但原对象未发生变化. 试想,有这种 ...

  10. C#6.0的新语法特性

    https://www.cnblogs.com/dotnet261010/p/9147707.html https://www.cnblogs.com/wangdodo/p/7929050.html