10-2总结

T1

dp,考试的时候想到统计方案然后暴力+乱搞,乱搞抽了只有30

dp[I][j]表示前i个数,j为xor后的值

//Copyright(c)2015 liuchenrui
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#define rep(i_) for(int i_=1;i_<=n;i_++)
using namespace std;
int ans;
int g[101][101];bool found;
inline void R(int &v)
{
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
int n;
int len[101];
int list[101][101];
int mc[101];
void dfs(int size)
{
	int i,j,k;
	if(len[size]==0)
	{
		if(size>ans)
		{
			ans=size;
			found=true;
		}
		return;
	}
	for(k=0;k<len[size] && !found;++k)
	{
		if(size+len[size]-k<=ans)
			break;
		i=list[size][k];
		if(size+mc[i]<=ans)
			break;
		for(j=k+1,len[size+1]=0;j<len[size];++j)
		{
			if(g[i][list[size][j]])
				list[size+1][len[size+1]++]=list[size][j];
		}
		dfs(size+1);
	}
}
void max_cluster()
{
	int i,j;
	mc[n]=ans=1;
	for(i=n-1;i;--i)
	{
		found=false;
		len[1]=0;
		for(j=i+1;j<=n;++j)
		{
			if(g[i][j])
				list[1][len[1]++]=j;
		}
		dfs(1);
		mc[i]=ans;
	}
}
int main()
{
	freopen("clique.in","r",stdin);
	freopen("clique.out","w",stdout);
	R(n);
	rep(i)rep(j)
	{
		int x;R(x);
		if(x==1)g[i][j]=true;
		if(i==j)g[i][j]=true;
	}
	max_cluster();
	printf("%d\n",ans);
	//fprintf(stderr,"%d\n",clock());
}

T2

裸的最大团,对拍盘盘T结果数据水爆,100



//Copyright(c)2015 liuchenrui
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#define ll long long
#define mod 1998585857
using namespace std;
inline void R(ll &v)
{
	v=0;char c=0;ll p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
ll n,a[10001];
ll t[1001];
ll ans=0;
ll ksm(ll a,ll b,ll c)
{
	ll ret=1;
	while(b>0)
	{
		if(b&1)ret=(1ll*ret*a)%c;
		b>>=1;
		a=(1ll*a*a)%c;
	}
		
	return ret;
}
ll dp[2][4096];
int main()
{
	freopen("set.in","r",stdin);
	freopen("set.out","w",stdout);
	R(n);
	for(int i=1;i<=n;i++)R(a[i]);
	dp[0][0]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=0;j<=4095;j++)
			dp[i&1][j]=(dp[(i-1)&1][j]+dp[(i-1)&1][j^a[i]]+dp[(i-1)&1][j^a[i]])%mod;
	ans=ksm(3,n,mod);
	ll tmp=ksm(2,mod-2,mod);
	ans=ans-(ll)dp[n&1][0];
	ans=1ll*ans*tmp%mod;
	ans=(ans%mod+mod)%mod;
	cout<<ans<<endl;
}

T3

反质数加强版,写了高精还是滚粗了,15

写不来代码= =


你可能感兴趣的:(dp,C语言)