D - Ears

思路:

s:起点           t:终点           l:左端点           r:右端点

以上称为关键点

dp[i][j]表示到位置 i 为止,已经经过前 j 个关键点的最小花费

转移方程看代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define y1 y11
  7. #define fi first
  8. #define se second
  9. #define pi acos(-1.0)
  10. #define LL long long
  11. //#define mp make_pair
  12. #define pb push_back
  13. #define ls rt<<1, l, m
  14. #define rs rt<<1|1, m+1, r
  15. #define ULL unsigned LL
  16. #define pll pair<LL, LL>
  17. #define pli pair<LL, int>
  18. #define pii pair<int, int>
  19. #define piii pair<pii, int>
  20. #define pdd pair<double, double>
  21. #define mem(a, b) memset(a, b, sizeof(a))
  22. #define debug(x) cerr << #x << " = " << x << "\n";
  23. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  24. //head
  25.  
  26. const int N = 2e5 + ;
  27. LL dp[N][];
  28. int a[N];
  29. int main() {
  30. int n;
  31. scanf("%d", &n);
  32. for (int i = ; i <= n; ++i) scanf("%d", &a[i]);
  33. for (int i = ; i <= n; i++) {
  34. dp[i][] = dp[i-][] + a[i];
  35. for (int j = ; j < ; j++) {
  36. dp[i][j] = dp[i-][j];
  37. for (int k = ; k < j; k++) dp[i][j] = min(dp[i][j], dp[i-][k]);
  38. }
  39. dp[i][] += a[i] == ? : (a[i]% != );
  40. dp[i][] += a[i]% != ;
  41. dp[i][] += a[i] == ? : (a[i]% != );
  42. dp[i][] += a[i];
  43. }
  44. LL ans = dp[n][];
  45. for (int i = ; i < ; i++) ans = min(ans, dp[n][i]);
  46. printf("%lld\n", ans);
  47. return ;
  48. }

Yahoo Programming Contest 2019 D - Ears的更多相关文章

  1. Yahoo Programming Contest 2019.D.Ears(DP)

    题目链接 菜爆了啊QAQ 记起点为\(S\),终点为\(T\),走过的最靠左的点是\(L\),最靠右的点是\(R\). 那么坐标轴被分成了五段: \(0\sim L-1\):经过\(0\)次: \(L ...

  2. [AtCoder] Yahoo Programming Contest 2019

    [AtCoder] Yahoo Programming Contest 2019   很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...

  3. Yahoo Programming Contest 2019 补题记录(DEF)

    D - Ears 题目链接:D - Ears 大意:你在一个\(0-L\)的数轴上行走,从整数格出发,在整数格结束,可以在整数格转弯.每当你经过坐标为\(i-0.5\)的位置时(\(i\)是整数),在 ...

  4. 【AtCoder】Yahoo Programming Contest 2019

    A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...

  5. Atcoder Yahoo Programming Contest 2019 简要题解

    A-C 直接放代码吧. A int n,k; int main() { n=read();k=read(); puts(k<=(n+1)/2?"YES":"NO&q ...

  6. Yahoo Programming Contest 2019

    A - Anti-Adjacency 签. #include <bits/stdc++.h> using namespace std; int main() { int n, k; whi ...

  7. Yahoo Programming Contest 2019 自闭记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  8. Yahoo Programming Contest 2019.E.Odd Subrectangles(思路 线性基)

    题目链接 \(Description\) 给定一个\(n\times m\)的\(01\)矩阵.求任意选出\(r\)行.\(c\)列(共\(2^{n+m}\)种方案),使得这\(r\)行\(c\)列的 ...

  9. Yahoo Programming Contest 2019.F.Pass(DP)

    题目链接 惊了这是什么F题...怎么我都能做出来...以后atcoder的比赛也不能走神了万一有个这样的F呢(CF已有多次了= =) \(f[i][j]\)表示Takahashi现在一共有\(i\)个 ...

随机推荐

  1. Codeforces 1100 - A/B/C/D/E/F - (Undone)

    链接:https://codeforces.com/contest/1100 A - Roman and Browser - [暴力枚举] 题意:浏览器有 $n$ 个网页,编号 $1 \sim n$, ...

  2. AndrewNG Deep learning课程笔记 - CNN

    参考, An Intuitive Explanation of Convolutional Neural Networks http://www.hackcv.com/index.php/archiv ...

  3. DELPHI中完成端口(IOCP)的简单分析(2)

    DELPHI中完成端口(IOCP)的简单分析(2)   今天我写一下关于DELPHI编写完成端口(IOCP)的工作者线程中的东西.希望各位能提出批评意见.上次我写了关于常见IOCP的代码,对于IOCP ...

  4. 高性能Nginx服务器-负载均衡

    Location正则表达式 location的作用 location指令的作用是根据用户请求的URI来执行不同的应用,也就是根据用户请求的网站URL进行匹配,匹配成功即进行相关的操作. locatio ...

  5. loadView

    loadView在View为nil时调用,早于ViewDidLoad,通常用于代码实现控件,收到内存警告时会再次调用.loadView默认做的事情是:如果此VIewcontroller存在一个对应的n ...

  6. 插入排序(Python实现)

    目录 1. for版本--插入排序 2. while版本--插入排序 3. 测试用例 4. 算法时间复杂度分析 1. for版本--插入排序 def insert_sort_for(a_list): ...

  7. js 判断浏览器型号

    <html><head> <meta http-equiv="Content-Type" content="text/html;charse ...

  8. vsCode工具做react开发,几个常用插件

    一.环境准备: 1.下载安装VSCode,Node.js,Yarn 2.打开命令行终端或powershell,输入yarn global add create-react-app安装react的脚手架 ...

  9. 027-Session状态提供程序

    Session分三种:1.InProc(进程内)-默认就是这种-速度快/但内存小/易丢失进程外:可以在IIS或ASPNET服务意外关闭时继续保持状态,注意此时存储到session中的对象必须支持序列化 ...

  10. Software Testing 2 —— Fault、error and failure小练习

    Questions: Below are two faulty programs. Each includes a test case that results in failure. Answer ...