版本比较
国庆day3考试总结--下午
正文
增加 61 行删除 2 行
12334567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465663 行未改动70717273157475767778168 行未改动全部展开# problem A### 错误点> 考场写出了拓扑写法,但是错了却A了8个点(~~真水~~),正确写法应该是> 考场写出了拓扑写法,但是错了却A了8个点(~~真水~~),正确写法应该是在求拓扑序的同时枚举26个字母,每个都要判断,然后用dp转移转移方程两个```cppif(b[tmp]==j)f[tmp][j]=max(f[tmp][j],f[k][j]+1); else f[tmp][j]=max(f[tmp][j],f[k][j]);```这里的f就是dp## problem A 正确代码``` cpp#include <bits/stdc++.h>#define int long longusing namespace std;const int N=1e6+5;int n,m,in[N],ans[N],tong[N],cnt;string s;vector<int> g[N];void topu_sort(){ queue<int> q; for(int i=1;i<=n;i++) { if(in[i]==0)q.push(i); } int cnt=0; while(!q.empty()) { int cur=q.front(); q.pop(); for(int i=0;i<g[cur].size();i++) { int nxt=g[cur][i]; in[nxt]--; if(in[nxt]==0) { ans[nxt]=max(ans[nxt],ans[cur]+1); q.push(nxt); } } } int maxn=-1e18; for(int i=1;i<=n;i++)maxn=max(maxn,ans[i]); if(maxn<=1)cout<<-1; else cout<<maxn; return ;}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin>>n>>m>>s; for(int i=1;i<=m;i++) { int x,y; cin>>x>>y; g[x].push_back(y); in[y]++; } topu_sort(); return 0;}```# problem B### 错误点```cppfor(int j=2;j<=n-1;j++)3 行未改动}```> 这个代码是正确的,但是我原来思路是一样的,但是我把所有的j都写成i了,其次还有没有清空,所以错了### 正确思路> 除了第一个人,其余全部按顺序建边,然后跑一遍拓扑,判断是否有环即可\> 除了第一个人,其余全部按顺序建边,然后跑一遍拓扑,判断是否有环即可```cppif(cnt==n)cout<<"YES";else cout<<"NO";```168 行未改动全部展开