Educational Codeforces Round 73

1334 (-2), pupil
Rank: 2668

(虽然比上次好,但是摆脱不了掉分的命运。。。)

D. Make The Fence Great Again

http://codeforces.com/contest/1221/problem/D

分析:对每个高度来说,最多升高两次,因此可以对这个进行dp(一开始读错题了,没有看到是相邻不能同高,一开始以为所有都不能同高)

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e6;
 4 typedef long long ll;
 5 const ll inf = 0x3f3f3f3f3f3f3f3f;
 6 int n;
 7 int h[maxn], w[maxn];
 8 ll dp[maxn][3];
 9
10 int main()
11 {
12     int T; cin >> T;
13     while (T--)
14     {
15         int n; cin >> n;
16         for (int i = 1; i <= n; i++)
17             scanf("%d%d", h + i, w + i);
18         for (int i = 1; i <= n; i++)
19             dp[i][0] = dp[i][1] = dp[i][2] = inf;
20         dp[1][0] = 0, dp[1][1] = w[1], dp[1][2] = 2 * w[1];
21         for (int i = 2; i <= n; i++)
22         {
23             for (int j = 0; j <= 2; j++)
24                 for (int k = 0; k <= 2; k++)
25                     if (h[i - 1] + j != h[i] + k)
26                         dp[i][k] = min(dp[i][k], w[i] * k + dp[i - 1][j]);
27         }
28         cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << endl;
29     }
30 }

原文地址:https://www.cnblogs.com/liuwenhan/p/11561495.html

时间: 2024-11-01 09:23:20

Educational Codeforces Round 73的相关文章

Educational Codeforces Round 73 (Rated for Div. 2)

比赛链接:Educational Codeforces Round 73 (Rated for Div. 2) 官方题解:Educational Codeforces Round 73 Editorial A. 2048 Game 题意 如果一个只包含 \(2\) 的幂次的集合,问能否从中选择一些数使得和为 \(2048\). 思路 不断合并直到凑到 \(2048\). 代码 #include <bits/stdc++.h> using namespace std; int main() {

Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again

题目链接:http://codeforces.com/contest/1221/problem/D 题意:给一个序列,要求修改某些位置的数字,使得这个序列的相邻的数不相等,每次修改,只能使得某个数字加一,每次修改的代价为b[i],求最小所需的代价. 解题思路:经过简单分析,我们可以知道,每个数字最多只需要修改两次,那么我们定义dp[i][j]使得前j个数字相邻数字不等的最小代价,且最后一个数字修改了i次.那么答案即为min{dp[0][n],dp[1][n],dp[2][n]}. #includ

Educational Codeforces Round 73 (Rated for Div. 2) A. 2048 Game

链接: https://codeforces.com/contest/1221/problem/A 题意: You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations wi

Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)

链接: https://codeforces.com/contest/1221/problem/B 题意: You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board. A knight is a chess pi

Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again(DP)

链接: https://codeforces.com/contest/1221/problem/D 题意: You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is ai. You think that the fence is great if there is no pair of adjacent boards having

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)

题目链接:Educational Codeforces Round 21 F. Card Game 题意: 有n个卡片,每个卡片有三个值:p,c,l; 现在让你找一个最小的L,使得满足选出来的卡片l<=L,并且所有卡片的p的和不小于k. 选择卡片时有限制,任意两张卡片的c之和不能为质数. 题解: 和hdu 1565 方格取数(2)一样,都是求最大点权独立集. 不难看出来,这题再多一个二分. 注意的是在构造二部图的时候,按照c值的奇偶性构造. 当c==1时要单独处理,因为如果有多个c==1的卡片,

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is