C. Gas Pipeline
A little bit
Solution:Express to
Root pillar, and the height of the pillar is
Minimum cost,
0 represents the height of the column 1.
1 means the height of the column is 2, the length of the string is n, there are n+1 columns in all, and the number of the column is 1 to n, then there are initial conditions.
The rest is initialized to
,
ConsiderIf it is `0', yes, both height pillars can be constructed, otherwise only 2 height pillars can be constructed. The answer is `0'.
,
The time complexity is
Code:
# define _CRT_SECURE_NO_WARNINGS #pragma GCC optimize(2) #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <cmath> #include <map> #include <vector> #include <queue> #define Pair pair<int,int> //#define int long long #define fir first #define sec second using namespace std; /*---------------------------------------------------------------------------------------------------------------------------*/ const int N = 2e5 + 5; const double pi = acos(-1.0); typedef long long ll; //const int mod = 998244353; const int mod = 1e9 + 7; #define inf 0x3f3f3f3f struct something { int num, period, time; bool operator < (const something& y)const { return y.time < time || (y.time == time && y.num < num); } something() {} something(int num, int period, int time) :num(num), period(period), time(time) {} }; int dx[8] = { 0, 0, 1,-1, 1, 1,-1,-1 }; int dy[8] = { 1,-1, 0, 0, 1,-1, 1,-1 }; char str[N]; ll f[N][2]; signed main() { int t; scanf("%d", &t); while (t--) { memset(f, 0x3f, sizeof f); int n, a, b; scanf("%d%d%d", &n, &a, &b); getchar(); scanf("%s", str + 1); //str[n + 1] = '0'; //printf("%s\n", str + 1); f[1][0] = b; for (int i = 2; i <= n + 1; i++) { if (str[i - 1] == '0') { f[i][0] = min(f[i - 1][0] + a + b, f[i - 1][1] + 2 * a + b); f[i][1] = min(f[i - 1][0] + 2 * b + 2 * a, f[i - 1][1] + 2 * b + a); } else f[i][1] = f[i - 1][1] + 2 * b + a; } printf("%lld\n", f[n + 1][0]); } return 0; }