9889

fujang
xiezere
lzl_3
bobo2010

skydegree
New_lzc

OnjoujiToki
QQ家族族长
Tilbur
zdca
xiaozihan
HH123_
Ditto_O
cdm
no_hard
SayonaraGzm

/*
IDA*这个算法的思想其实比A*要好理解很多

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
using namespace std;
const int N = 30;
int di[10][N];
int qi[N];
int n;
int f()
{
int cnt=0;
for(int i=1;i<=n-1;i++)
{
if(qi[i]+1!=qi[i+1])cnt++;
}
return (cnt+2)/3;
}
bool check()
{
for(int i=1;i<=n-1;i++)
{
if(qi[i]+1!=qi[i+1])return false;
}
return true;
}
bool dfs(int u,int depth)
{
if(u+f()>depth)return false;
if(check())return true;
for(int len=1;len<=n;len++)
{
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
for(int k=j+1;k<=n;k++)
{
int y=i;
memcpy(di[u+1],qi,sizeof qi);
for(int d=j+1;d<=k;d++,y++)
{
qi[y]=di[u+1][d];
}
for(int d=i;d<=j;d++,y++)
{
qi[y]=di[u+1][d];
}
if(dfs(u+1,depth))return true;
memcpy(qi,di[u+1],sizeof qi);
}
}
}
return false;
}
int main()
{
int t;
cin >> t;
while(t--)
{

cin >> n;
for(int i=1;i<=n;i++)
{
cin >> qi[i];
}
int depth=0;
while(depth<5&&!dfs(0,depth))depth++;
if(depth>=5) cout << "5 or more"<<endl;
else cout << depth<<endl;
}
return 0;
}


/*

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
#define int long long
using namespace std;
int dp[1<<25],ans;
int ai[50];
int m,n;
int cnt;
bool cmp(int a,int b)
{
return a>b;
}
void dfs(int u,int k,int sum)
{
if(u>k)
{
dp[++cnt]=sum;
return;
}
dfs(u+1,k,sum);
if(sum+ai[u]<=m)dfs(u+1,k,sum+ai[u]);
}
void dfs1(int u,int sum)
{
if(u>n)
{
int l=1,r=cnt;
while(l<r)
{
int mid=l+r+1>>1;
if(dp[mid]+sum<=m)l=mid;
else r=mid-1;
}
ans=max(ans,dp[l]+sum);
return;
}
dfs1(u+1,sum);
if(sum+ai[u]<=m)dfs1(u+1,sum+ai[u]);
}
signed main()
{
cin >> m>>n;
for(int i=1;i<=n;i++)
cin >> ai[i];
sort(ai+1,ai+1+n,cmp);
int k=n/2+2;
dfs(1,k,0);
sort(dp+1,dp+cnt+1);
dfs1(k+1,0);
cout << ans<<endl;
return 0;
}


/*

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
using namespace std;
int ans[110];
int n;
bool dfs(int u,int depth)
{
if(u>depth)return false;
if(u==depth&&ans[u]==n)return true;
if(u==depth&&ans[u]!=n)return false;
int st[110]={0};
for(int i=1;i<=u;i++)
{
for(int j=1;j<=u;j++)
{
int t=ans[i]+ans[j];
if(st[t]||t>n||t<ans[u])continue;
st[t]=1;
ans[u+1]=t;
if(dfs(u+1,depth))return true;
}
}
return false;
}
int main()
{
while(cin>>n)
{
if(n==0)break;
ans[1]=1;
int depth=2;
if(n==1)
{
cout << 1<<endl;
continue;
}
while(!dfs(1,depth))depth++;
for(int i=1;i<=depth;i++)
cout << ans[i]<<" ";
cout << endl;
}
return 0;
}


/*

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
#include <vector>
#define int long long
using namespace std;
const int N = 5e5+10;
int sum[N],sum1[N];
int pre[N];
int cnt=0;
int st[N];
int ge(int n,int p)
{
if(n<p)return 0;
return n/p+ge(n/p,p);
}
void inti(int n)
{
for(int i=2;i<=n;i++)
{
if(st[i]==0)
{
pre[cnt++]=i;
}
for(int j=0;pre[j]*i<=n;j++)
{
st[i*pre[j]]=1;
if(i%pre[j]==0)break;
}
}
}
vector<int> mul(vector<int> a, int b)
{
vector<int> c;
for(int i=0;i<a.size();i++)
{
}
{
}
while(c.size()>1&&c[c.size()-1]==0)
{
c.pop_back();
}
return c;
}
vector<int> sub(vector<int> &A, vector<int> &B)
{
vector<int> C;
for (int i = 0, t = 0; i < A.size(); i ++ )
{
t = A[i] - t;
if (i < B.size()) t -= B[i];
C.push_back((t + 10) % 10);
if (t < 0) t = 1;
else t = 0;
}

while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
signed main()
{
inti(N-10);
int n,m;
cin >> n>>m;
vector<int> ans1,ans2;
ans1.push_back(1),ans2.push_back(1);
for(int i=0;i<cnt;i++)
{
int p=pre[i];
sum[i]=ge(n+m,p)-ge(m,p)-ge(n,p);
}
for(int i=0;i<cnt;i++)
{
int p=pre[i];
sum1[i]=ge(n+m,p)-ge(m-1,p)-ge(n+1,p);
}
for(int i=0;i<cnt;i++)
{
for(int j=1;j<=sum[i];j++)
{
ans1=mul(ans1,pre[i]);
}
}
for(int i=0;i<cnt;i++)
{
for(int j=1;j<=sum1[i];j++)
{
ans2=mul(ans2,pre[i]);
}
}
ans1=sub(ans1,ans2);
for(int i=ans1.size()-1;i>=0;i--)
cout << ans1[i];
cout << endl;
return 0;
}


/*

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
#define int long long
using namespace std;
const int N = 100;
int f[55][50050];
int dp(int a,int b)
{
if(f[a][b]!=-1)return f[a][b];
if(!a)return f[a][b]=b%2;
if(b==1)return dp(a+1,0);
if(a&&!dp(a-1,b))return f[a][b]=1;
if(a>=2&&!dp(a-2,b+(b?3:2)))return f[a][b]=1;
if(b&&!dp(a,b-1))return f[a][b]=1;
if(b>=2&&!dp(a,b-1))return f[a][b]=1;
if(a&&b&&!dp(a-1,b+1))return f[a][b]=1;
return f[a][b]=0;
}
signed main()
{
int t;
cin >> t;
memset(f,-1,sizeof f);
while(t--)
{
int n;
cin >> n;
int a=0,b=0;
for(int i=1;i<=n;i++)
{
int x;
cin >> x;
if(x==1)a++;
else if(b==0)b+=x;
else b+=x+1;
}
if(dp(a,b)) cout << "YES"<<endl;
else cout << "NO"<<endl;
}
return 0;
}


/*

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
using namespace std;
const int N = 10010;
const int M = 60010;
int s;
int h[N],ne[M],e[M],idx;
int dfn[N],low[N],tim;
void add(int a,int b)
{
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int cnt;
int foot;
void tarjan(int u,int fa)
{
dfn[u]=low[u]=++tim;
int oi=0;
for(int i=h[u];i!=-1;i=ne[i])
{
int j=e[i];
if(!dfn[j])
{
tarjan(j,u);
low[u]=min(low[u],low[j]);
if(low[j]>=dfn[u])
{
oi++;
}
}
else low[u]=min(low[u],dfn[j]);
}
if(u!=foot&&cnt>0)oi++;
s=max(s,oi);
}
int main()
{
int n,m;
while(cin>>n>>m)
{
if(n==0&&m==0)break;
memset(h,-1,sizeof h);
idx=0;
cnt=0,s=0;
tim=0;
memset(dfn,0,sizeof dfn);
memset(low,0,sizeof low);
for(int i=1;i<=m;i++)
{
int a,b;
cin >> a>>b;
}
for(int i=0;i<n;i++)
{
if(!dfn[i])
{
cnt++;
foot=i;
tarjan(i,-1);
}
}
cout << cnt+s-1<<endl;
}
return 0;
}


/*

*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
#include<stack>
#define int long long
using namespace std;
const int N = 5010;
const int M = 2e5+10;
int h[N],e[M],ne[M],idx;
int dfn[N],low[N],tim;
int id[N];
int d[N];
int st[M];
int scc;
void add(int a,int b)
{
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
stack<int> si;
void tarjan(int u,int fa)
{
dfn[u]=low[u]=++tim;
si.push(u);
for(int i=h[u];i!=-1;i=ne[i])
{
int j=e[i];
if(!dfn[j])
{
tarjan(j,i);
low[u]=min(low[u],low[j]);
if(low[j]>dfn[u])
{
st[i]=1;
st[i^1]=1;
}
}
else if(i!=(fa^1))
{
low[u]=min(low[u],dfn[j]);
}
}
if(dfn[u]==low[u])
{
scc++;
int p;
do
{
p=si.top();
si.pop();
id[p]=scc;
}while(p!=u);
}
}
signed main()
{
int n,m;
cin >> n>>m;
memset(h,-1,sizeof h);
for(int i=1;i<=m;i++)
{
int a,b;
cin >> a>>b;
}
tarjan(1,-1);
for(int i=0;i<idx;i++)
{
if(st[i])
{
d[id[e[i]]]++;
}
}
int cnt=0;
for(int i=1;i<=scc;i++)
{
if(d[i]==1)cnt++;
}
cout << (cnt+1)/2<<endl;
return 0;
}


//这里填你的代码^^
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


# include[HTML_REMOVED]

using namespace std;
const int N = 110;
int p[N];
int find(int x)
{
if(x!=p[x])p[x]=find(p[x]);
return p[x];
}
int ai[200010];
int di[200010];
int main()
{
int n;
cin >> n;
for(int i=1;i<=n;i)
{
cin >> ai[i];
}
for(int i=1;i<=n;i
)
{
cin >> di[i];
}
for(int i=1;i<=n;i)p[i]=i;
for(int i=1;i<=n;i
)
{
if(i+di[i]<=n)
{
int a=find(i),b=find(i+di[i]);
p[a]=b;
}
if(i-di[i]>=1)
{
int a=find(i),b=find(i-di[i]);
p[a]=b;
}
}
int flag=1;
for(int i=1;i<=n;i++)
{
if(find(ai[i])==find(i));
else flag=0;
}
if(flag) cout << “YES”<<endl;
else cout << “NO”<<endl;

return 0;


}