Cow Hopscotch
Cow Hopscotch
题目描述
The game is played on an R by C grid (2 <= R <= 750, 2 <= C <= 750), where each square is labeled with an integer in the range 1..K (1 <= K <= R*C). Cows start in the top-left square and move to the bottom-right square by a sequence of jumps, where a jump is valid if and only if
1) You are jumping to a square labeled with a different integer than your current square,
2) The square that you are jumping to is at least one row below the current square that you are on, and
3) The square that you are jumping to is at least one column to the right of the current square that you are on.
Please help the cows compute the number of different possible sequences of valid jumps that will take them from the top-left square to the bottom-right square.
输入
输出
样例输入
4 4 4
1 1 1 1
1 3 2 1
1 2 4 1
1 1 1 1
样例输出
5
分析:2个难点,状态转移和分治处理;
状态转移:ans[x][y]=∑ans[i][j](i<x,j<y)-Σans[i][j](i<x,j<y,a[i][j]=a[x][y]);
分治:由于处理左半部分,上半部分时和右半部分,下半部分没有半毛钱关系,所以分治处理;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,a[maxn][maxn],ans[maxn][maxn],check[maxn*maxn];
void gao(int l,int r)
{
if(l==r)return;
int mid=l+r>>;
gao(l,mid);
memset(check,,sizeof(check));
int all=;
for(int j=;j<=m;j++)
{
for(int i=mid+;i<=r;i++)
ans[i][j]=((ans[i][j]+all-check[a[i][j]])%mod+mod)%mod;
for(int i=l;i<=mid;i++)
all+=ans[i][j],all%=mod,check[a[i][j]]+=ans[i][j],check[a[i][j]]%=mod;
}
gao(mid+,r);
}
int main()
{
int i,j;
scanf("%d%d%d",&n,&m,&k);
rep(i,,n)rep(j,,m)scanf("%d",&a[i][j]);
ans[][]=;
gao(,n);
printf("%d\n",ans[n][m]);
//system("pause");
return ;
}
Cow Hopscotch的更多相关文章
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- 【洛谷】2990:[USACO10OPEN]牛跳房子Cow Hopscotch【单调队列优化DP】
P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing ...
- 洛谷P3120 [USACO15FEB]Cow Hopscotch
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented ...
- 【bzoj3939】[Usaco2015 Feb]Cow Hopscotch 动态开点线段树优化dp
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a varian ...
- 洛谷 P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)
P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold) 就像人类喜欢跳格子游戏一样,FJ的奶牛们发明了一种新的跳格子游戏.虽然这种接近一吨的笨拙的动物玩跳格子游戏几 ...
- Cow Hopscotch (单调队列 + DP)
链接:https://ac.nowcoder.com/acm/contest/1113/K来源:牛客网 The cows have reverted to their childhood and ar ...
- 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& ...
- bzoj3939 【USACO 2015 FEB GOLD 】cow hopscotch
Description 就像人类喜欢玩"跳房子"的游戏,农民约翰的奶牛已经发明了该游戏的一个变种自己玩.由于笨拙的动物体重近一吨打,牛跳房子几乎总是以灾难告终,但这是没有阻止奶牛几 ...
- BZOJ1915[USACO 2010 Open Gold 1.Cow Hopscotch]——DP+斜率优化
题目描述 奶牛们正在回味童年,玩一个类似跳格子的游戏,在这个游戏里,奶牛们在草地上画了一行N个格子,(3 <=N <= 250,000),编号为1..N.就像任何一个好游戏一样,这样的跳格 ...
随机推荐
- linux文件权限赋值
1修改权限 命令:chmod (change mode) 功能:改变文件的读写和执行权限.有符号法和八进制数字法. 选项:(1)符号法: 命令格式:chmod {u|g|o ...
- ecshop 去版权
与官网通信的几个地方: 1,打开admin/templates/index.htm,查找并删除 <frameset rows="0, 0" framespacing=&quo ...
- abstract class 和 interface区别
相同点: 1.都不能被直接实例化,都可以通过继承实现其抽象方法: 不同点: 1.接口支持多继承,抽象类只能由一个父类: 2.接口只能定义行为,抽象类既可以定义行为,又可以提供实现: 3.接口只包含方法 ...
- 建立TCP连接的三次握手
请求端(通常称为客户)发送一个 SYN 报文段( SYN 为 1 )指明客户打算连接的服务器的端口,以及初始顺序号( ISN ).服务器发回包含服务器的初始顺序号( ISN )的 SYN 报文段( S ...
- 标签—box-shadow
box-shadow:2px 3px 4px #CCC; 一个带外阴影的元素,阴影位置x轴偏移2px,y轴偏移3px,模糊范围4px,阴影颜色#CCC box-shadow:inset 0 -4px ...
- poi 合并单元格、设置边框
HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); //创建一个样式 HSSFCellStyle sty ...
- 最短路径问题/Spfa
题目链接 题目描述 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线, 则输出花费最少的. 最后一行是两个数 s,t;起 ...
- Android中如何将Bitmap byte裸数据转换成Bitmap图片int数据
Android中如何将Bitmap byte裸数据转换成Bitmap图片int数据 2014-06-11 10:45:14 阅读375次 我们在JNI中处理得到的BMP图片Raw数据,我们应该如何 ...
- Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整(原理:底层SurfaceView+上层绘制ImageView)
Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整实现(原理:底层SurfaceView+上层绘制ImageView) 分类: Android开发 Androi ...
- margin
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...