首页 技术 正文
技术 2022年11月21日
0 收藏 393 点赞 3,896 浏览 2566 个字

题目:http://www.51nod.com/onlineJudge/questionCode.html

很好的思想。考虑从小到大一对一对填数,这样也能对它的大小限制做一些操作了。

因为从小到大,所以只能全填在左边、全填在右边、两边各填一个。记录左边填到了哪个位置,就可知右边填到了哪个位置。转移之前判断一下这样填是否合法即可。

新的不合法的状态只会和现在填的两个位置有关。

注意输入格式!!符号前后有空格!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=,M=;
int n,m,x[M],y[M],sgn[M],tx,ty;
ll dp[N][N<<],ans;
char ch[];
bool check(int p0,int p1,int r,int fx)
{
//printf("p0=%d p1=%d r=%d fx=%d\n",p0,p1,r,fx);
for(int i=;i<=m;i++)
if(sgn[i]==&&
( ( (x[i]==p0||x[i]==p1)&&y[i]!=p0&&y[i]!=p1)||
( (y[i]==p0||y[i]==p1)&&x[i]!=p0&&x[i]!=p1) ) )
return ;//以前都合法,不合法仅出现在p0、p1位置上
if(!fx)
{
for(int i=;i<=m;i++)
{
//printf("sgn[%d]=%d\n",i,sgn[i]);
if(sgn[i]==||sgn[i]==)
{
tx=x[i];ty=y[i];
if(sgn[i]==)swap(tx,ty);
//printf("tx=%d ty=%d p0=%d p1=%d r=%d\n",tx,ty,p0,p1,r);
if((ty==p0||ty==p1)&&tx>=p0&&tx<r) return ;
}
if(sgn[i]==||sgn[i]==)
{
tx=x[i];ty=y[i];
if(sgn[i]==)swap(tx,ty);
if((ty==p0||ty==p1)&&tx>p1&&tx<r) return ;
}
}
}
if(fx==)
{
for(int i=;i<=m;i++)
{
if(sgn[i]==||sgn[i]==)
{
tx=x[i];ty=y[i];
if(sgn[i]==)swap(tx,ty);
if((ty==p0||ty==p1)&&tx<=p1&&tx>r) return ;
}
if(sgn[i]==||sgn[i]==)
{
tx=x[i];ty=y[i];
if(sgn[i]==)swap(tx,ty);
if((ty==p0||ty==p1)&&tx<p0&&tx>r) return ;
}
}
}
if(fx==)
{
for(int i=;i<=m;i++)
{
if(sgn[i]==||sgn[i]==)
{
tx=x[i];ty=y[i];
if(sgn[i]==)swap(tx,ty);
if((ty==p0||ty==p1)&&tx>=p0&&tx<=p1) return ;
}
if(sgn[i]==||sgn[i]==)
{
tx=x[i];ty=y[i];
if(sgn[i]==)swap(tx,ty);
if((ty==p0||ty==p1)&&tx>p0&&tx<p1) return ;
}
}
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);ch[]=getchar();
while(ch[]!='\n')ch[]=getchar();
for(int i=,len=,j;i<=m;i++,len=)
{
ch[++len]=getchar();
while(ch[len]!='\n')ch[++len]=getchar();
for(j=;j<len;j++)
{
if(ch[j]>=''&&ch[j]<='')
x[i]=(x[i]<<)+(x[i]<<)+ch[j]-'';
else break;
}
while(ch[j]==' ')j++;
//printf("j=%d chj=(%c)\n",j,ch[j]);
if(ch[j]=='=') sgn[i]=,j++;
else if(ch[j]=='<'&&ch[j+]=='=')sgn[i]=,j+=;
else if(ch[j]=='>'&&ch[j+]=='=')sgn[i]=,j+=;
else if(ch[j]=='<')sgn[i]=,j++;
else if(ch[j]=='>')sgn[i]=,j++;
while(ch[j]==' ')j++;
//printf("j=%d chj=(%c)\n",j,ch[j]);
for(;j<len;j++)
y[i]=(y[i]<<)+(y[i]<<)+ch[j]-'';
//printf("x=%d sgn=%d y=%d\n",x[i],sgn[i],y[i]);
}
dp[][]=;
for(int i=,lm;i<n;i++)
{
lm=(i<<);
for(int j=,r;j<=lm;j++)
{
//if(dp[i][j])printf("dp[%d][%d]=%lld\n",i,j,dp[i][j]);
r=(n<<)-(lm-j)+;
if(check(j+,j+,r,))
dp[i+][j+]+=dp[i][j];
//printf("dp[%d][%d]=%lld(%d,%d)\n",i+1,j+2,dp[i+1][j+2],i,j);
if(check(r-,r-,j,))
dp[i+][j]+=dp[i][j];
//printf("dp[%d][%d]=%lld(%d,%d)\n",i+1,j,dp[i+1][j],i,j);
if(check(j+,r-,,))
dp[i+][j+]+=dp[i][j];
//printf("dp[%d][%d]=%lld(%d,%d)\n",i+1,j+1,dp[i+1][j+1],i,j);
}
}
int lm=(n<<);
for(int j=;j<=lm;j++) ans+=dp[n][j];
printf("%lld\n",ans/);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848