BZOJ3427 Poi2013 Bytecomputer

可以YY一下嘛= =

最后一定是-1, -1, ..., -1, 0, 0, ... 0, 1, 1, ..., 1的一个数列

于是f[i][j]表示到了第i个数,新数列的第j项为-1 or 0 or 1的的最小代价

然后就没有然后了

 1 /**************************************************************
 2     Problem: 3427
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:808 ms
 7     Memory:16432 kb
 8 ****************************************************************/
 9
10 #include <cstdio>
11 #include <cstring>
12 #include <algorithm>
13
14 using namespace std;
15 const int N = 1000005;
16 const int inf = 1e9;
17
18 int a[N], f[N][3];
19 int n, ans = inf;
20
21 inline int read() {
22     int x = 0, sgn = 1;
23     char ch = getchar();
24     while (ch < ‘0‘ || ‘9‘ < ch) {
25         if (ch == ‘-‘) sgn = -1;
26         ch = getchar();
27     }
28     while (‘0‘ <= ch && ch <= ‘9‘) {
29         x = x * 10 + ch - ‘0‘;
30         ch = getchar();
31     }
32     return sgn * x;
33 }
34
35 int main() {
36     int i, j, k;
37     int t, to;
38     n = read();
39     for (i = 1; i <= n; ++i)
40         a[i] = read();
41     memset(f, 127, sizeof(f));
42     f[1][a[1] + 1] = 0;
43     for (i = 1; i < n; ++i)
44         for (j = 0; j <= 2; ++j) if (f[i][j] < inf)
45             for (t = j - 1, k = 0; k <= 2; ++k) {
46                 to = a[i + 1] + k * t;
47                 if (to >= -1 && to <= 1 && to >= t)
48                     f[i + 1][to + 1] = min(f[i + 1][to + 1], f[i][j] + k);
49             }
50     for (i = 0; i <= 2; ++i)
51         ans = min(ans, f[n][i]);
52     if (ans == inf) puts("BRAK");
53     else printf("%d\n", ans);
54     return 0;
55 }

时间: 2024-07-28 17:59:25

BZOJ3427 Poi2013 Bytecomputer的相关文章

POI2013 Bytecomputer

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3427 可以证明最终序列为-1...0....1 因为首先如果 a(i-1) 为-1或0,执行操作不会让答案变优. 然后,如果可以加到大于1的某个数字,一定可以加到1,显然加到1更佳. 然后简单dp,f[i][j]表示第i位为j的最少步数. #include <cstdio> #include <cstring> #include <algorithm> #defin

(DP) POI Bytecomputer

Bytecomputer Memory limit: 128 MB A sequence of  integers  from the set  is given. The bytecomputer is a device that allows the following operation on the sequence: incrementing  by  for any . There is no limit on the range of integers the bytecomput

【BZOJ3425】Poi2013 Polarization 猜结论+DP

[BZOJ3425]Poi2013 Polarization Description 给定一棵树,可以对每条边定向成一个有向图,这张有向图的可达点对数为树上有路径从u到达v的点对(u,v)个数.求最小可达点对数和最大可达点对数 n<=250000 Sample Input 4 1 2 1 3 1 4 Sample Output 3 5 题解:想了一晚上,怎么想怎么是个搭建双塔,结果看题解发现还真tm是搭建双塔. 本题的结论有点神,不过很好猜,证明见Claris博客. 第一问的答案一定是n-1,因

【BZOJ3417】Poi2013 Tales of seafaring 分层图BFS

[BZOJ3417]Poi2013 Tales of seafaring Description 一个n点m边无向图,边权均为1,有k个询问 每次询问给出(s,t,d),要求回答是否存在一条从s到t的路径,长度为d 路径不必是简单路(可以自交) 2<=N<=5000,1<=M<=5000,1<=K<=1000000,1<=d<=1000000000 Sample Input 8 7 4 1 2 2 3 3 4 5 6 6 7 7 8 8 5 2 3 1 1

[POI2013]BAJ-Bytecomputer

题目描述 A sequence of integers from the set is given. The bytecomputer is a device that allows the following operation on the sequence: incrementing by for any . There is no limit on the range of integers the bytecomputer can store, i.e., each can (in p

[POI2013]?uk triumfalny

[POI2013]?uk triumfalny 题目大意: 一棵\(n(n\le3\times10^5)\)个结点的树,一开始\(1\)号结点为黑色.\(A\)与\(B\)进行游戏,每次\(B\)能选择不超过\(k\)个结点染成黑色,然后\(A\)从当前点出发走到一个相邻的结点.若\(A\)从\(1\)号结点出发,则\(k\)最小取多少能保证\(A\)每次走到的点都是黑点? 思路: 二分答案\(k\)后使用树形DP判断是否可行. 从叶子往根考虑,\(f_i\)表示将\(i\)的子树全部染黑需要从

P3558 [POI2013]BAJ-Bytecomputer

题目描述 A sequence of integers is given. The bytecomputer is a device that allows the following operation on the sequence: incrementing for any. There is no limit on the range of integers the bytecomputer can store, i.e., each can (in principle) have ar

【题解】[P3557 POI2013]GRA-Tower Defense Game

[题解][P3557 POI2013]GRA-Tower Defense Game 这道题是真的** 根据题目给的\(k\),可以知道,我们随便放塔,只要不全放一起,一定是一种合法的方案. 直接枚举就好了,脑子都不用,时间复杂度\(O(n)\) #include<bits/stdc++.h> using namespace std; #define RP(t,a,b) for(register int t=(a),edd=(b);t<=edd;++t) #define DRP(t,a,b

BZOJ3421 : Poi2013 Walk

最多只有一个连通块大小大于$nk$,所以用hash表进行BFS的时候只扩展$nk$步即可. 时间复杂度$O(n^2k)$. #include<cstdio> typedef long long ll; const int N=5001000,M=9999991; int n,m,lim,i,h=1,t,g[M],nxt[N],ed;ll v[N],a[N/5],q[N],x,S,T;char s[70]; inline void del(ll x){ int u=x%M; v[ed]=x;nx