Yahoo Programming Contest 2019 D - Ears
思路:
s:起点 t:终点 l:左端点 r:右端点
以上称为关键点
dp[i][j]表示到位置 i 为止,已经经过前 j 个关键点的最小花费
转移方程看代码:
- #pragma GCC optimize(2)
- #pragma GCC optimize(3)
- #pragma GCC optimize(4)
- #include<bits/stdc++.h>
- using namespace std;
- #define y1 y11
- #define fi first
- #define se second
- #define pi acos(-1.0)
- #define LL long long
- //#define mp make_pair
- #define pb push_back
- #define ls rt<<1, l, m
- #define rs rt<<1|1, m+1, r
- #define ULL unsigned LL
- #define pll pair<LL, LL>
- #define pli pair<LL, int>
- #define pii pair<int, int>
- #define piii pair<pii, int>
- #define pdd pair<double, double>
- #define mem(a, b) memset(a, b, sizeof(a))
- #define debug(x) cerr << #x << " = " << x << "\n";
- #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- //head
- const int N = 2e5 + ;
- LL dp[N][];
- int a[N];
- int main() {
- int n;
- scanf("%d", &n);
- for (int i = ; i <= n; ++i) scanf("%d", &a[i]);
- for (int i = ; i <= n; i++) {
- dp[i][] = dp[i-][] + a[i];
- for (int j = ; j < ; j++) {
- dp[i][j] = dp[i-][j];
- for (int k = ; k < j; k++) dp[i][j] = min(dp[i][j], dp[i-][k]);
- }
- dp[i][] += a[i] == ? : (a[i]% != );
- dp[i][] += a[i]% != ;
- dp[i][] += a[i] == ? : (a[i]% != );
- dp[i][] += a[i];
- }
- LL ans = dp[n][];
- for (int i = ; i < ; i++) ans = min(ans, dp[n][i]);
- printf("%lld\n", ans);
- return ;
- }
Yahoo Programming Contest 2019 D - Ears的更多相关文章
- Yahoo Programming Contest 2019.D.Ears(DP)
题目链接 菜爆了啊QAQ 记起点为\(S\),终点为\(T\),走过的最靠左的点是\(L\),最靠右的点是\(R\). 那么坐标轴被分成了五段: \(0\sim L-1\):经过\(0\)次: \(L ...
- [AtCoder] Yahoo Programming Contest 2019
[AtCoder] Yahoo Programming Contest 2019 很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...
- Yahoo Programming Contest 2019 补题记录(DEF)
D - Ears 题目链接:D - Ears 大意:你在一个\(0-L\)的数轴上行走,从整数格出发,在整数格结束,可以在整数格转弯.每当你经过坐标为\(i-0.5\)的位置时(\(i\)是整数),在 ...
- 【AtCoder】Yahoo Programming Contest 2019
A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...
- 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 ...
- Yahoo Programming Contest 2019
A - Anti-Adjacency 签. #include <bits/stdc++.h> using namespace std; int main() { int n, k; whi ...
- Yahoo Programming Contest 2019 自闭记
A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
- Yahoo Programming Contest 2019.E.Odd Subrectangles(思路 线性基)
题目链接 \(Description\) 给定一个\(n\times m\)的\(01\)矩阵.求任意选出\(r\)行.\(c\)列(共\(2^{n+m}\)种方案),使得这\(r\)行\(c\)列的 ...
- Yahoo Programming Contest 2019.F.Pass(DP)
题目链接 惊了这是什么F题...怎么我都能做出来...以后atcoder的比赛也不能走神了万一有个这样的F呢(CF已有多次了= =) \(f[i][j]\)表示Takahashi现在一共有\(i\)个 ...
随机推荐
- Codeforces 1100 - A/B/C/D/E/F - (Undone)
链接:https://codeforces.com/contest/1100 A - Roman and Browser - [暴力枚举] 题意:浏览器有 $n$ 个网页,编号 $1 \sim n$, ...
- AndrewNG Deep learning课程笔记 - CNN
参考, An Intuitive Explanation of Convolutional Neural Networks http://www.hackcv.com/index.php/archiv ...
- DELPHI中完成端口(IOCP)的简单分析(2)
DELPHI中完成端口(IOCP)的简单分析(2) 今天我写一下关于DELPHI编写完成端口(IOCP)的工作者线程中的东西.希望各位能提出批评意见.上次我写了关于常见IOCP的代码,对于IOCP ...
- 高性能Nginx服务器-负载均衡
Location正则表达式 location的作用 location指令的作用是根据用户请求的URI来执行不同的应用,也就是根据用户请求的网站URL进行匹配,匹配成功即进行相关的操作. locatio ...
- loadView
loadView在View为nil时调用,早于ViewDidLoad,通常用于代码实现控件,收到内存警告时会再次调用.loadView默认做的事情是:如果此VIewcontroller存在一个对应的n ...
- 插入排序(Python实现)
目录 1. for版本--插入排序 2. while版本--插入排序 3. 测试用例 4. 算法时间复杂度分析 1. for版本--插入排序 def insert_sort_for(a_list): ...
- js 判断浏览器型号
<html><head> <meta http-equiv="Content-Type" content="text/html;charse ...
- vsCode工具做react开发,几个常用插件
一.环境准备: 1.下载安装VSCode,Node.js,Yarn 2.打开命令行终端或powershell,输入yarn global add create-react-app安装react的脚手架 ...
- 027-Session状态提供程序
Session分三种:1.InProc(进程内)-默认就是这种-速度快/但内存小/易丢失进程外:可以在IIS或ASPNET服务意外关闭时继续保持状态,注意此时存储到session中的对象必须支持序列化 ...
- Software Testing 2 —— Fault、error and failure小练习
Questions: Below are two faulty programs. Each includes a test case that results in failure. Answer ...