社区讨论
建议加强数据
P1983[NOIP 2013 普及组] 车站分级参与者 1已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lzpm55fo
- 此快照首次捕获于
- 2024/08/11 21:41 2 年前
- 此快照最后确认于
- 2024/08/14 14:07 2 年前
这道题是什么神仙题目?怎么 的时间复杂度也能过?(题解区第一篇题解就是 的)
我的代码是差分约束+记忆化搜索,时间复杂度 :
CPP#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2010;
vector<pair<ll,ll> > e[N];
ll n,m,dis[N],ans;
bool st[N];
ll dfs(ll u) {
if(dis[u]) return dis[u];
dis[u]=1;
for(ll i=0; i<e[u].size(); ++i) {
ll v=e[u][i].first,w=e[u][i].second;
dis[u]=max(dis[u],dfs(v)+w);
}
return dis[u];
}
int main() {
freopen("level.in","r",stdin);
freopen("level.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(ll i=1,s,x; i<=m; ++i) {
cin>>s;
memset(st,0,sizeof(st));
ll str=n,end=0;
while(s--) {
cin>>x;
st[x]=1;
str=min(str,x),end=max(end,x);
}
for(ll j=str; j<=end; ++j)
if(st[j]) e[n+i].push_back({j,1});
else e[j].push_back({n+i,0});
}
for(ll i=1; i<=n; ++i) ans=max(ans,dfs(i));
cout<<ans;
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...