158人阅读 评论(0)

# 250

## Solution

1$-1$分别替换为0,1,2$0,1,2$来判断答案是否变化即可。简单粗暴

## Code

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
LL gao(vector<int> a) {
stack<LL> S;
int n = a.size();
for (int i = 0; i < 100; ++i)   S.push(0);
for (int i = 0; i < n; ++i) {
if (!a[i]) {
LL x = S.top();
S.pop();
LL y = S.top();
S.pop();
S.push(x + y);
}
else S.push(a[i]);
}
return S.top();
}
struct Suminator {
int findMissing(vector <int> a, int S) {
int n = a.size();
int p;
for (int i = 0; i < n; ++i)
if (a[i] == -1) p = i;
a[p] = 0;
LL t = gao(a);
if (t == S) return 0;
a[p] = 1;
LL u = gao(a);
a[p] = 2;
LL v = gao(a);
if (u == v) return -1;
if (u <= S) return S - u + 1;
return -1;
}
};

# 500

## Code

#include <bits/stdc++.h>//dp
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55, M = 1e9 + 7;
int n, m;
int dp[N][N][3][2][2];
bool bw[N][N], wb[N][N];
int f(int x, int y, int dir, int ok1, int ok2) {
if (x == n) {
if (y == m && dir == 2) return 0;
return ok1 + ok2;
}
int &t = dp[x][y][dir][ok1][ok2];
if (~t) return t;
t = 0;
for (int num = 0; num <= m; ++num) {
if (dir == 0 && num < y || dir == 1 && num > y) continue;
int ndir = dir;
if (dir == 2 && num < y)    ndir = 1;
if (dir == 2 && num > y)    ndir = 0;
if (x == 0) ndir = 2;
if (y == m && num == 0) continue;
int t1 = ok1, t2 = ok2;
if (!bw[x][num])    t1 = 0;
if (!wb[x][num])    t2 = 0;
(t += f(x + 1, num, ndir, t1, t2)) %= M;
}
return t;
}
struct TwoConvexShapes {
int countWays(vector <string> grid) {
n = grid.size(), m = grid[0].size();
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; ++i)
for (int j = 0; j <= m; ++j) {
bw[i][j] = 1;
for (int k = 0; k < j; ++k)
if (grid[i][k] == 'W')  bw[i][j] = 0;
for (int k = j; k < m; ++k)
if (grid[i][k] == 'B')  bw[i][j] = 0;
wb[i][j] = 1;
for (int k = 0; k < j; ++k)
if (grid[i][k] == 'B')  wb[i][j] = 0;
for (int k = j; k < m; ++k)
if (grid[i][k] == 'W')  wb[i][j] = 0;
}
int ans = 0;
(ans += f(0, 0, 2, 1, 1)) %= M;
return ans;

}
};
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：43291次
• 积分：1317
• 等级：
• 排名：千里之外
• 原创：86篇
• 转载：0篇
• 译文：0篇
• 评论：17条
评论排行
最新评论