当前位置:网站首页>L3-1 那就别担心了 (30 分)——坑点,测试点分析
L3-1 那就别担心了 (30 分)——坑点,测试点分析
2022-04-21 22:12:00 【Echo_ac】
思路
题目就是求从 A A A 到 B B B 的路径条数,和判断从 A A A 的路径是否都经过 B B B 。我们采用记忆化搜索来加速即可。
这里主要为了说一下坑点,题目可能出现这样的情况:
从 A A A 到 B B B 完全符合题目的条件,但是很多朋友可能没处理好,大家测测这个例子即可。
5 5
1 2
2 3
3 5
4 5
2 4
1 2

AC代码
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define per(i,x,y) for(int i=x; i>=y; --i)
#define pushk push_back
#define popk pop_back
#define mem(a,b) memset(a,b,sizeof a)
#define ll long long
#define lp p<<1
#define rp p<<1|1
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
const int N = 520;
vector<int> g[N];
int A,B;
int cnt1=0,cnt2=0;
ll dp[N];
int f[N][N];
ll dfs(int u) {
if(dp[u]) return dp[u];
if(g[u].size()==0) {
if(u==B) dp[u]=1;
else dp[u]=0;
return dp[u];
}
if(u==B) return dp[u]=1;
ll res=0;
for(auto &it : g[u]) {
res+=dfs(it);
}
return dp[u]=res;
}
ll dfs2(int u) {
if(dp[u]) return dp[u];
if(g[u].size()==0) {
return dp[u]=1;
}
if(u==B) return dp[u]=1;
ll res=0;
for(auto &it : g[u]) {
res+=dfs2(it);
}
return dp[u]=res;
}
int main() {
int n,m;
cin>>n>>m;
rep(i,1,m) {
int u,v;
cin>>u>>v;
g[u].pushk(v);
f[u][v]=1;
}
cin>>A>>B;
ll ans=dfs(A);
rep(i,1,n) dp[i]=0;
ll tmp=dfs2(A);
cout<<ans<<" ";
if(tmp==ans) puts("Yes");
else puts("No");
return 0;
}
版权声明
本文为[Echo_ac]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45769627/article/details/124294112
边栏推荐
- [ES6] function extension
- Because the epidemic makes the garment industry fully realize the necessity of digital transformation.
- The @ select annotation is used in the mapper of mybtais, and the if annotation is used
- Compilation interrupt
- EventBridge 集成云服务实践
- Mypinpad and smartpesa merged to become the global leader in mobile payment acceptance
- The development of China's industrial Internet industry has achieved remarkable results, but the technical challenge is still a long-term project
- Download and install the vscade plug-in package offline
- Echart writes a large screen showing a circular edge gradient histogram
- Software life cycle
猜你喜欢

Vscode 插件包下载并离线安装

IDEA通过Jedis操作Linux上的Redis;Failed to connect to any host resolved for DNS name问题

Do you have any good suggestions for brushing questions and how to improve efficiency?

ROS——使用OpenCV实现摄像头的发送和接收

解放双手,推荐一款阿里开源的低代码工具,YYDS~

Classification of software testing and principles of software testing

Leetcode0785. Judgement bipartite graph (DFS)
![[MySQL] solve the problem of MAC accessing MySQL server on windows](/img/45/53ef2fe3abed114148340787226260.png)
[MySQL] solve the problem of MAC accessing MySQL server on windows
![[JVM] 10 interview questions](/img/68/6c1c24e8c847612412241a4cd4fe2e.png)
[JVM] 10 interview questions

Short video live broadcast mode enables agricultural products in remote areas to "go global"
随机推荐
云原生微服务的下一站,微服务引擎 MSE 重磅升级
ES6 how to find the intersection of two arrays
数据库事务学习总结
Oracle cascade delete table (not subject to foreign key constraints)
Serviceworker cache and HTTP cache
Smart Chemical Park solutions
面试必刷算法TOP101之背包九讲篇 TOP13
CPT 102_LEC 11
[ES6] module import and export
Oracle级联删除表(不受外键约束)
EventBridge 集成云服务实践
Interview must brush algorithm top101 knapsack nine lectures top14
INT 102_TTL 09
Oracle合并数据操作(MERGE)
【ES6】Promise
Intensive reading of Fanfan's anti attack paper (II) CVPR 2021 yuan learning training simulator for ultra efficient black box attack (Tsinghua)
The @ select annotation is used in the mapper of mybtais, and the if annotation is used
【ES6】Generator
Idea operates redis on Linux through jedis; Failed to connect to any host resolved for DNS name
es6如何求两个数组的交集