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 之和要最小. 题解: 运用贪心的思 ...
随机推荐
- Python中的线程详解
线程 常用的方法 import threading import time def hello(name): print('Hello %s' % name) # 阻塞 time.sleep(5) p ...
- Tomcat常用设置及安全管理规范
前言 随着公司内部使用Tomcat作为web应用服务器的规模越来越大,为保证Tomcat的配置安全,防止信息泄露,恶性攻击以及配置的安全规范,特制定此Tomcat安全配置规范.注意: 本文章从htt ...
- input text 只能输入数字
添加 onkeyup="value=value.replace(/[^\d]/g,'')"
- 450. Delete Node in a BST 删除bst中的一个节点
[抄题]: Given a root node reference of a BST and a key, delete the node with the given key in the BST. ...
- AndFix注意事项
1.生成补丁,修改前后的apk包都必须签名. 2.AndFix 不支持修改布局文件. 3.文件的路径必须正确. 4.AndFix 不支持添加匿名内部类(就是点击事件). 5.AndFix 不支持添加新 ...
- c#关于Mysql MySqlBulkLoader 批量上传
有个list表有几万数据 用insert插入,速度跟蜗牛爬行, 几十个表,传起来可就需要时间了. 搜搜,发现有 MySqlBulkLoader 这个人家mysql 的dll 里边已经提供了这个方法 ...
- GUI学习之一——PyQt5初识
我们在第〇篇里先演示了GUI的功能,其实Python有多个库是支持GUI编程的,python官网列出了大量的说明,其中包括了原生的tkinter 还有许多第三方库 Pyqt PySide wxPyth ...
- tcp、ip、http
tcp是传输层协议,ip是网络层协议,http是应用层协议,简单说就是tcp是传输数据,而http是封装数据. rpc与http的区别是项目大的话,接口间调用变多的话,采用rpc的话,不用像http那 ...
- PowerDesigner 缺省值 引号 问题
在使用PowerDesigner做为MySQL数据库建模的时候,总是有这样的问题,例如我需要一个字段 createTime 类型是 Timestamp,要求这个字段默认值为系统当前时间,于是我给这个字 ...
- mysql空值排序
SELECT * FROM lzh_topic_channel_product ORDER BY order_id is null , order_id 其中的ORDER BY order_id i ...