hdu 5116--Everlasting L(计数DP)
2018-06-17 22:20:27来源:未知 阅读 ()
题目链接
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.
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; const int N=40050; const int M=205; 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==0)?a:gcd(b,a%b); } void init() { for(int i=1;i<M;i++) for(int j=1;j<M;j++) { dp[i][j]=dp[i][j-1]+((gcd(i,j)==1)?1:0); cnt[i][j]=cnt[i-1][j]+dp[i][j]; } } int main() { init(); int T,Case=1; cin>>T; while(T--) { int n; scanf("%d",&n); memset(mp,0,sizeof(mp)); memset(U,0,sizeof(U)); memset(R,0,sizeof(R)); memset(t,0,sizeof(t)); for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); mp[x][y]=1; } for(int i=200;i>=1;i--) { for(int j=200;j>=1;j--) { if(mp[i][j]){ if(mp[i+1][j]) U[i][j]=U[i+1][j]+1; if(mp[i][j+1]) R[i][j]=R[i][j+1]+1; } } } LL s=0; for(int i=1;i<=200;i++) { for(int j=1;j<=200;j++) { if(mp[i][j]){ s+=cnt[U[i][j]][R[i][j]]; int d=0; for(int k=U[i][j];k>=0;k--) { d+=dp[k][R[i][j]]; t[i+k][j]+=d; } } } } LL ans=0; for(int i=1;i<=200;i++) { for(int j=1;j<=200;j++) { if(mp[i][j]){ LL p=t[i][j]; LL pp=cnt[U[i][j]][R[i][j]]; p-=pp; for(int k=1;k<=R[i][j];k++) { p+=t[i][j+k]; ans+=2*p*dp[k][U[i][j]]; } ans+=pp*pp; } } } s=s*s-ans; printf("Case #%d: %lld\n",Case++,s); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash