比赛 |
2025暑期集训第7场 |
评测结果 |
A |
题目名称 |
天气预报 |
最终得分 |
100 |
用户昵称 |
OTTF |
运行时间 |
0.333 s |
代码语言 |
C++ |
内存使用 |
103.71 MiB |
提交时间 |
2025-08-11 17:29:37 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int need[400][5][5];
int dp[400][4][4][8][8][8][8];
int xc[9] = {-1, 0, -2, 0, 2, 0, 1, 0, 0};
int yc[9] = {0, -1, 0, -2, 0, 2, 0, 1, 0};
bool check(int day, int x, int y) {
for (int i = x; i <= x + 1; i++) {
for(int j = y; j <= y + 1; j++) {
if(need[day][i][j] == 1) {
return false;
}
}
}
return true;
}
int dfs (int day, int x, int y, int zs, int zx, int ys, int yx) {
// cout << day << ' ' << x << ' ' << y << ' ' << zs << ' ' << zx << ' ' << ys << ' ' << yx << endl;
if (dp[day][x][y][zs][zx][ys][yx] != -1) {
return dp[day][x][y][zs][zx][ys][yx];
}
if (!check (day, x, y)) {
return 0;
}
if (zs >= 7 || zx >= 7 || ys >= 7 || yx >= 7) {
return 0;
}
if (day == n) {
return 1;
}
int res = 0;
for (int i = 0; i < 9; i++) {
int xx = x + xc[i];
int yy = y + yc[i];
if (1 <= xx && xx <= 3 && 1 <= yy && yy <= 3) {
int new_zs = (xx == 1 && yy == 1) ? 0 : zs + 1;
int new_zx = (xx == 3 && yy == 1) ? 0 : zx + 1;
int new_ys = (xx == 1 && yy == 3) ? 0 : ys + 1;
int new_yx = (xx == 3 && yy == 3) ? 0 : yx + 1;
res |= dfs (day + 1, xx, yy, new_zs, new_zx, new_ys, new_yx);
}
}
dp[day][x][y][zs][zx][ys][yx] = res;
return res;
}
int main () {
freopen ("weather_forecast.in", "r", stdin);
freopen ("weather_forecast.out", "w", stdout);
while (cin >> n, n) {
memset (dp, -1, sizeof (dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 4; j++) {
for (int k = 1; k <= 4; k++) {
cin >> need[i][j][k];
}
}
}
cout << dfs (1, 2, 2, 1, 1, 1, 1) << endl;
}
return 0;
}