BZOJ3939 : [Usaco2015 Feb]Cow Hopscotch
设f[i][j]表示到(i,j)的方案数,则有
$f[i][j]=\sum f[x][y](x<i,y<j,a[x][y]!=a[i][j])=\sum f[x][y](x<i,y<j)-\sum f[x][y](x<i,y<j,a[x][y]==a[i][j])$
然后运用CDQ分治即可$O(nm\log n)$解决。
#include<cstdio>
const int N=752,P=1000000007;
int n,m,k,i,j,a[N][N],f[N][N],T,all,s[N*N],v[N*N];
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
void solve(int l,int r){
if(l==r)return;
int mid=(l+r)>>1;
solve(l,mid);
for(T++,all=0,j=1;j<=m;j++){
for(i=r;i>mid;i--){
if(v[a[i][j]]<T)v[a[i][j]]=T,s[a[i][j]]=0;
f[i][j]=((f[i][j]+all-s[a[i][j]])%P+P)%P;
}
for(i=l;i<=mid;i++){
if(v[a[i][j]]<T)v[a[i][j]]=T,s[a[i][j]]=0;
(s[a[i][j]]+=f[i][j])%=P,(all+=f[i][j])%=P;
}
}
solve(mid+1,r);
}
int main(){
read(n),read(m),read(k);
for(i=f[1][1]=1;i<=n;i++)for(j=1;j<=m;j++)read(a[i][j]);
solve(1,n);
return printf("%d",f[n][m]),0;
}
BZOJ3939 : [Usaco2015 Feb]Cow Hopscotch的更多相关文章
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- 【bzoj3939】[Usaco2015 Feb]Cow Hopscotch 动态开点线段树优化dp
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a varian ...
- BZOJ 3939 [Usaco2015 Feb]Cow Hopscotch ——线段树 CDQ分治
显然dp[i][j]=ps[i-1][j-1]-sigma(dp[k<i][l<j],a[i][j]=a[k][l]) 考虑对于每一种颜色都开一颗区间线段树,但是空间不够. 所以我们可以动 ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
[BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...
- 3942: [Usaco2015 Feb]Censoring [KMP]
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 375 Solved: 206[Subm ...
- Bzoj3943 [Usaco2015 Feb]SuperBull
3943: [Usaco2015 Feb]SuperBull Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 300 Solved: 185 Desc ...
- bzoj3940: [Usaco2015 Feb]Censoring
AC自动机.为什么洛谷水题赛会出现这种题然而并不会那么题意就不说啦 .终于会写AC自动机判断是否是子串啦...用到kmp的就可以用AC自动机水过去啦 #include<cstdio> #i ...
- BZOJ1631: [Usaco2007 Feb]Cow Party
1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 459 Solved: 338[Submit ...
随机推荐
- lucas定理,组合数学问题
对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况.就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 这里用到Lusac定理 ...
- nyoj 8
http://acm.nyist.net/JudgeOnline/problem.php?pid=8 #include<stdio.h> #include<iostream> ...
- NYOJ 106背包问题
http://acm.nyist.net/JudgeOnline/problem.php?pid=106 背包问题 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现 ...
- tar: Removing leading `/’ from member names
tar: Removing leading `/’ from member names+2 分类:Web服务器 标签:tar 3,910人浏览 这并不是一个错误,而是一个警告,原因很简单,就是你在 ...
- 【Hibernate】Hibernate系列1之概述
概述 Hibernate简介 1.2.安装hibernate tools插件 1.3.HelloWorld示例 1.3.1.加入jar包 1.3.2.开发步骤 hibernate generator ...
- iOS 中使用类别简化代码开发
最近需要一个函数,把CLLocation对象转化为NSDictionary,按照我以前的想法,我会写一个工具类,之后添加一个函数,类似这样 - (NSDictionary *)turnLocation ...
- (原创)Python文件与文件系统系列(5)——stat模块
stat模块中定义了许多的常量和函数,可以帮助解释 os.stat().os.fstat().os.lstat()等函数返回的 st_result 类型的对象. 通常使用 os.path.is*() ...
- Java for LeetCode 155 Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- [产品相关] A/B测试终极指南(翻译)
转载地址: http://blog.sina.com.cn/s/blog_9149268d0100zrx7.html 还记得以前导师说看了英文的文章就把它翻译一下吧,这样会对文章更好地理解,也会有更深 ...
- php 基础语法
<?php //注释 /* 多行注释 */ //输出语句 //echo "hello","helloa"; //print "world&quo ...