BZOJ2087 : [Poi2010]Sheep
一条边能连上当且仅当它没有经过任何点,并且两边的点都是偶数个。
枚举原点,通过极角排序求出哪些边是合法的,然后区间DP即可。
时间复杂度$O(nm\log m+n^3)$。
#include<cstdio>
#include<algorithm>
const int N=610,M=20010;
int n,m,P,cnt,i,j,k,t,now,f[N][N];bool g[N][N],v[N][N];
struct vec{int x,y,p;vec(){}vec(int _x,int _y){x=_x,y=_y;}vec operator-(const vec&b){return vec(x-b.x,y-b.y);}
}a[N],b[M],c[N+M],O;
inline int cross(vec a,vec b){return a.x*b.y-a.y*b.x;}
inline bool cmp(vec x,vec y){return cross(x-O,y-O)<0;}
int dp(int l,int r){if(l+1==r)return 1;if(v[l][r])return f[l][r];v[l][r]=1;int&t=f[l][r];for(int i=l+1;i<r;i++)if(g[i][l]&&g[i][r])t=(t+dp(l,i)*dp(i,r))%P;return t;
}
int main(){scanf("%d%d%d",&n,&m,&P);for(i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);for(i=1;i<=m;i++)scanf("%d%d",&b[i].x,&b[i].y);O=a[1];std::sort(a+2,a+n+1,cmp);for(i=1;i<=n;i++)a[i].p=i;for(i=1;i<=n;i++){O=a[i];cnt=0;for(j=1;j<=n;j++)if(j!=i)c[++cnt]=a[j];for(j=1;j<=m;j++)c[++cnt]=b[j];std::sort(c+1,c+cnt+1,cmp);for(j=1,t=0;j<=cnt;j=k){for(now=0,k=j;k<=cnt&&!cross(c[k]-O,c[j]-O);k++)if(!c[k].p)now++;if(!now&&!t)for(k=j;k<=cnt&&!cross(c[k]-O,c[j]-O);k++)if(c[k].p)g[i][c[k].p]=g[c[k].p][i]=1;t^=now&1;}}return printf("%d",dp(1,n)),0;
}
转载于:https://www.cnblogs.com/clrs97/p/5939811.html
BZOJ2087 : [Poi2010]Sheep相关推荐
- bzoj2091: [Poi2010]The Minima Game DP
2091: [Poi2010]The Minima Game DP 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2091 思路 这类问题好迷 ...
- P3511 [POI2010]MOS-Bridges(网络流/欧拉回路)
P3511 [POI2010]MOS-Bridges 给出一个图,边正着走和反着走的边权不同,求解最大边权最小的欧拉回路,输出方案. 首先看到最大边权最小我们就可以想到二分答案,然后现在在剩余的图上我 ...
- 【HDU - 6016】Count the Sheep (思维,类似二分图)
题干: Altough Skipping the class is happy, the new term still can drive luras anxious which is of cour ...
- 【bzoj2084】[Poi2010]Antisymmetry
2084: [Poi2010]Antisymmetry Time Limit: 10 Sec Memory Limit: 259 MB Submit: 1205 Solved: 756 [Subm ...
- 2091: [Poi2010]The Minima Game
2091: [Poi2010]The Minima Game 链接 分析: 首先排序后,一定是选的连续的一段. f[i]表示前i个位置,先手-后手的最大得分. 那么考虑第i个位置是否选,如果选,先手选 ...
- Arranging The Sheep
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep ...
- CF1520E Arranging The Sheep
题目描述 You are playing the game "Arranging The Sheep". The goal of this game is to make the ...
- Arranging The Sheep(移动思维)
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep ...
- Day 5 E. Arranging The Sheep
Problem: You are playing the game "Arranging The Sheep". The goal of this game is to make ...
最新文章
- 如何将Visio图形转换成EPS格式【mark from百度知道】
- JAVA——[MySQLNonTransientConnectionException:Could not create connection to database server.]解决方案
- JAVA异步爬虫_Java 爬虫遇上数据异步加载,试试这两种办法!
- Win32ASM学习[14]:符号扩展指令: CBW,CWDE,CDQ,CWD
- 所需依赖_注意细节,阿里架构师一文详解SpringDI的四种依赖注入方式
- oracle中的fetchsize,oracle setFetchsize() 优化查询速度
- python3 asyncio 不阻塞_Python中的并发处理之asyncio包使用的详解
- Android UI设计秘笈
- 2021高考成绩河北查询时间,2021年高考成绩什么时候出来-2021高考成绩公布时间...
- FillForm网页表单填写插件(用于火狐浏览器,自动填表,自动表单,填写表单)
- 基于Gromacs的蜘蛛毒素肽显性溶剂动力学分析
- RTI路由服务入门手册
- MSP430 G2553 单片机 口袋板 日历 时钟 闹钟 万年历 电子时钟 秒表显示
- 【Kotlin学习之旅】使用Kotlin实现常见的对称加密、非对称加密、消息摘要、数字签名的demo
- axios封装request配置
- Altium Designer原理图转PCB板时报错是什么原因?
- 海信linux系统信息,海信公交车数据采集系统 调试信息
- win7打开网络无计算机,Win7电脑系统IPV6无网络访问权限解决方法
- Java虚拟机学习与总结(二)
- 计算机实时控制和过程控制,实时控制程序
热门文章
- SPRING IN ACTION 第4版笔记-第二章-002-@ComponentScan、@Autowired的用法
- placeholder=请输入用户名(六位数字加英文字母)
- VMware共享文件夹遇到的问题
- Jquery使用$.Post方法,本地可以,服务器错误的处理方法...
- 【转CSDN常高伟】如何学习一门新的语言
- PostgreSQL 8.4.3 Final / 9.0 Alpha 4
- Semantic Web 文章目录
- CentOS7 linux下yum安装redis以及使用
- c# nat udp转发
- 画了个Android