跳到正文

个人记录

T491588 【CCR系列】【T1】找啊找啊找朋友 题解

chrisxu1约 3 分钟
原文
文章信息与版本

文章信息

发布
2024年8月6日
收录
2026年5月29日
更新
2026年11月15日
篇幅
约 3 分钟
获赞
1

版本

  1. v1当前
C++
#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<queue>
#define ll long long
using namespace std;
int a, b, n, m, dp[4005][4005];
bool vis[4005][4005], vis1[4005][4005];
struct node{
	int first_x, first_y;
	int second_x, second_y;
};
node c[4005];
int main(){
	//freopen("fraction.in","r",stdin);
	//freopen("fraction.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);
	memset(vis, 1, sizeof(vis));
	cin >> n >> m;
	cin >> a;
	for(int i = 1; i <= a; i ++){
		ll x, y;
		cin >> x >> y;
		vis[x][y] = 0;
	}
	cin >> b;
	for(int i = 1; i <= b; i ++){
		cin >> c[i].first_x >> c[i].first_y >> c[i].second_x >> c[i].second_y;
		vis1[c[i].second_y][c[i].second_y] = 1;
	}
	dp[1][1] = 1;
	if(vis[1][1] == 0){
		cout << -1;
		return 0;
	}
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			if((i == 1 && j == 1) || vis[i][j] == 0){
				continue;
			}
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			if(vis1[i][j] == 0){
				for(int k = 1; k <= b; k ++){
					if(c[k].second_x == i && c[k].second_y == j){
						dp[i][j] += dp[c[k].first_x][c[k].first_y];
					}
				}
			}
		}
	}
	if(dp[n][m] == 0){
		cout << -1;
		return 0;
	}
	cout << dp[n][m];
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}
原文