hdu 5116--Everlasting L(计数DP)
A point set P is (a, b)-L if and only if there exists x, y satisfying:
P = {(x, y), (x + 1, y), . . . , (x + a, y), (x, y + 1), . . . , (x, y + b)}(a, b ≥ 1)
A point set Q is good if and only if Q is an (a, b)-L set and gcd(a, b) = 1.
Matt is given a point set S. Please help him find the number of ordered pairs of sets (A, B) such that:
For each test case, the first line contains an integer N (0 ≤ N ≤ 40000), indicating the size of the point set S.
Each of the following N lines contains two integers xi, yi, indicating the i-th point in S (1 ≤ xi, yi ≤ 200). It’s guaranteed that all (xi, yi) would be distinct.
n the second sample, the ordered pairs of sets Matt can choose are:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=;
const int M=;
int R[M][M],U[M][M];
bool mp[M][M];
int dp[M][M],cnt[M][M];
int t[M][M]; int gcd(int a,int b) { return (b==)?a:gcd(b,a%b); } void init()
{
for(int i=;i<M;i++)
for(int j=;j<M;j++)
{
dp[i][j]=dp[i][j-]+((gcd(i,j)==)?:);
cnt[i][j]=cnt[i-][j]+dp[i][j];
}
}
int main()
{
init();
int T,Case=;
cin>>T;
while(T--)
{
int n; scanf("%d",&n);
memset(mp,,sizeof(mp));
memset(U,,sizeof(U));
memset(R,,sizeof(R));
memset(t,,sizeof(t));
for(int i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x][y]=;
}
for(int i=;i>=;i--)
{
for(int j=;j>=;j--)
{
if(mp[i][j]){
if(mp[i+][j]) U[i][j]=U[i+][j]+;
if(mp[i][j+]) R[i][j]=R[i][j+]+;
}
}
}
LL s=;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(mp[i][j]){
s+=cnt[U[i][j]][R[i][j]];
int d=;
for(int k=U[i][j];k>=;k--)
{
d+=dp[k][R[i][j]];
t[i+k][j]+=d;
}
}
}
}
LL ans=;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(mp[i][j]){
LL p=t[i][j];
LL pp=cnt[U[i][j]][R[i][j]];
p-=pp;
for(int k=;k<=R[i][j];k++)
{
p+=t[i][j+k];
ans+=*p*dp[k][U[i][j]];
}
ans+=pp*pp;
}
}
}
s=s*s-ans;
printf("Case #%d: %lld\n",Case++,s);
}
return ;
}
hdu 5116--Everlasting L(计数DP)的更多相关文章
- 动态规划(DP计数):HDU 5116 Everlasting L
Matt loves letter L.A point set P is (a, b)-L if and only if there exists x, y satisfying:P = {(x, y ...
- HDU 5116 Everlasting L
题目链接:HDU-5116 题意:给定若干个整数点,若一个点集满足P = {(x, y), (x + 1, y), . . . , (x + a, y), (x, y + 1), . . . , (x ...
- HDU 4055 Number String (计数DP)
题意:由数字1到n组成的所有排列中,问满足题目所给的n-1个字符的排列有多少个,如果第i字符是‘I’表示排列中的第i-1个数是小于第i个数的. 如果是‘D’,则反之. 析:dp[i][j] 表示前 i ...
- HDU 6377 度度熊看球赛 (计数DP)
度度熊看球赛 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- HDU 4632 CF 245H 区间DP(回文)
先说HDU 4632这道题,因为比较简单,题意就是给你一个字符串,然后给你一个区间,叫你输出区间内所有的回文子序列,注意是回文子序列,不是回文字串. 用dp[i][j]表示区间[i,j]内的回文子序列 ...
- HDU 5693 D Game 区间dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5693 题解: 一种朴实的想法是枚举选择可以删除的两个或三个数(其他的大于三的数都能凑成2和3的和), ...
- hdu 2829 Lawrence(斜率优化DP)
题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...
- hdu 3480 Division(斜率优化DP)
题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思 ...
随机推荐
- [leetcode]341. Flatten Nested List Iterator展开嵌套列表的迭代器
Given a nested list of integers, implement an iterator to flatten it. Each element is either an inte ...
- 通过github安装crawley出现的问题
http://www.cnblogs.com/hbwxcw/p/7086188.html
- FT_ND_API.dll
ePass1000ND https://blog.csdn.net/li34442779/article/details/44276989 https://www.cnblogs.com/lidabo ...
- tomcat的缺少tcnative-1.dll的解决
tomcat启动出现如下问题: The APR based Apache Tomcat Native library which allows optimal performance in produ ...
- P1613 跑路(倍增 + floyd)
https://www.luogu.org/problemnew/show/P1613 思路: 1.读入 2.建图 3.对于每一个点,向距离它 2^k 长度的点连一条长度为 1 的边 4.在新图上跑1 ...
- 使用Shell脚本对Linux系统和进程资源进行监控
ShellLinux脚本 摘要:Shell语言对于接触Linux的人来说都比较熟悉,它是系统的用户界面,提供了用户与内核进行交互操作的一种接口.本文我们以Bash做为实例总结了使用Shell对系统和进 ...
- jxl操作excel写入数据不覆盖原有数据示例
public void readTO() { Workbook wb = null; WritableWorkbook wwb = null; try { ...
- Python开发——6.文件操作
一.文件操作 1.文件操作的处理流程 打开文件得到文件句柄并赋值给一个变量====>通过句柄对文件进行分析====>关闭文件 #1. 打开文件,得到文件句柄并赋值给一个变量 f=open( ...
- Ngui分辨率适配
必备知识点 1.分辨率适配必然是Orthographic Camera 2.Camera下对应的“Size”(图1)属性大小的理解:当前摄像机高度 = Size * 2 * UnityUnit(Uni ...
- Js之设置日期时间 判断日期是否在范围内
var now = new Date(); var startDate = new Date(); startDate.setFullYear(2018, 08, 07); startDate.set ...