Cow Hopscotch

题目描述

Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a variant of the game for themselves to play. Being played by clumsy animals weighing nearly a ton, Cow Hopscotch almost always ends in disaster, but this has surprisingly not deterred the cows from attempting to play nearly every afternoon.

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.

输入

The first line contains the integers R, C, and K. The next R lines will each contain C integers, each in the range 1..K.

输出

Output the number of different ways one can jump from the top-left square to the bottom-right square, mod 1000000007.

样例输入

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的更多相关文章

  1. 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树

    [BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...

  2. 【洛谷】2990:[USACO10OPEN]牛跳房子Cow Hopscotch【单调队列优化DP】

    P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing ...

  3. 洛谷P3120 [USACO15FEB]Cow Hopscotch

    题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John&apos;s cows have invented ...

  4. 【bzoj3939】[Usaco2015 Feb]Cow Hopscotch 动态开点线段树优化dp

    题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a varian ...

  5. 洛谷 P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)

    P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold) 就像人类喜欢跳格子游戏一样,FJ的奶牛们发明了一种新的跳格子游戏.虽然这种接近一吨的笨拙的动物玩跳格子游戏几 ...

  6. Cow Hopscotch (单调队列 + DP)

    链接:https://ac.nowcoder.com/acm/contest/1113/K来源:牛客网 The cows have reverted to their childhood and ar ...

  7. 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& ...

  8. bzoj3939 【USACO 2015 FEB GOLD 】cow hopscotch

    Description 就像人类喜欢玩"跳房子"的游戏,农民约翰的奶牛已经发明了该游戏的一个变种自己玩.由于笨拙的动物体重近一吨打,牛跳房子几乎总是以灾难告终,但这是没有阻止奶牛几 ...

  9. BZOJ1915[USACO 2010 Open Gold 1.Cow Hopscotch]——DP+斜率优化

    题目描述 奶牛们正在回味童年,玩一个类似跳格子的游戏,在这个游戏里,奶牛们在草地上画了一行N个格子,(3 <=N <= 250,000),编号为1..N.就像任何一个好游戏一样,这样的跳格 ...

随机推荐

  1. IOS设备上网页中的页面滚动效果模拟

    可能咋一看不知道我说的是个啥,因为iOS本来就用这功能的啊,还模拟它干啥?先听我说下项目背景哈 我现在开发的是一个webapp,主要是用在ipad上,这个app的大小是固定大小的,为了防止触摸它出现弹 ...

  2. JPG、PNG和GIF图片的基本原理及优化方法

    一提到图片,我们就不得不从位图开始说起,位图图像(bitmap),也称为点阵图像或绘制图像,是由称作像素(图片元素)的单个点组成的.这些点可以进行不同的排列和染色以构成一副图片.当放大位图时,可以看见 ...

  3. codeforce div2 C 树状数组

    http://codeforces.com/contest/362 题目大意:给你一个序列,用冒泡排序法让他变为非递减的序列最少需要几次.在冒泡交换之间,你有一个swap操作,该swap操作是交换任意 ...

  4. Django CRM学员系统项目

    项目需求: 1.分讲师\学员\课程顾问角色,2.学员可以属于多个班级,学员成绩按课程分别统计3.每个班级至少包含一个或多个讲师4.一个学员要有状态转化的过程 ,比如未报名前,报名后,毕业老学员5.客户 ...

  5. Sanatorium

    Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  6. web配置文件的<load-on-startup>0</load-on-startup>

    在servlet的配置当中,<load-on-startup>5</load-on-startup>的含义是:标记容器是否在启动的时候就加载这个servlet.当值为0或者大于 ...

  7. Android实现GIF图片解码与播放

    Android实现GIF图片解码与播放 如何在Android中播放GIF图片呢?如果直接按以前的方法,分解图片,可能相对比较麻烦. 今天给大伙介绍一种新的方式,构造自己的Android图片解码帮助类, ...

  8. 在WIN7/8下把XP装入VHD (下)

    系统平台:win8.1,安装在C盘 操作目的:在win8.1下装一个VHD  XP. 操作方法: 在http://www.cnblogs.com/mahocon/p/5212914.html里贴了一个 ...

  9. nagios安装全过程

    Nagios是一个用来监控主机.服务和网络的开放源码软件,可以在发生故障时发送报警短信和邮件,只要Nagios监控的对象发生故障,系统就会自动发送短信到手机上.所以应用十分广泛. Nagios is  ...

  10. java数据结构之链表的实现

    这个链表的内部是使用双向链表来表示的,但是并未在主函数中进行使用 /** * 链表 * 2016/4/26 **/ class LinkList{ Node head = new Node(); No ...