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+10;
const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}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>>1;gao(l,mid);memset(check,0,sizeof(check));int all=0;for(int j=1;j<=m;j++){for(int i=mid+1;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+1,r);
}
int main()
{int i,j;scanf("%d%d%d",&n,&m,&k);rep(i,1,n)rep(j,1,m)scanf("%d",&a[i][j]);ans[1][1]=1;gao(1,n);printf("%d\n",ans[n][m]);//system("pause");return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/5775569.html

Cow Hopscotch相关推荐

  1. USACO比赛题泛刷

    随时可能弃坑. 因为不知道最近要刷啥所以就决定刷下usaco. 优先级排在学习新算法和打比赛之后. 仅有一句话题解.难一点的可能有代码. 优先级是Gold>Silver.Platinum刷不动. ...

  2. POJ 3258 -- River Hopscotch(二分)

    题目链接 Description Every year the cows hold an event featuring a peculiar version of hopscotch that in ...

  3. 二分+最大化最小值 River Hopscotch POJ - 3258

    题意: 起始有两个石头,位置是000和nnn,在这中间有n个石头,问如何拿走m块石头后,使得他们之间的最小间隔的最大值. 题目: Every year the cows hold an event f ...

  4. River Hopscotch

    题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total ...

  5. bzoj 1650: [Usaco2006 Dec]River Hopscotch 跳石子(二分)

    1650: [Usaco2006 Dec]River Hopscotch 跳石子 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 721  Solved: ...

  6. 【二分法】POJ3258-River Hopscotch

    [抱大腿]啊啊啊又是一道恶心的题目!!!这道题是出在二分法里面的,因为这跟前面的一道青蛙过河的题特别像但是不一样,按照青蛙过河那个思路来走根本行不通,正好要按照跟那个思路相反的想法来想才行~ [题目] ...

  7. POJ3258River Hopscotch题解

    POJ3258River Hopscotch题解 题目 链接 字面描述 思路 重点 代码实现 题目 链接 http://poj.org/problem?id=3258 字面描述 River Hopsc ...

  8. River Hopscotch问题(二分)

    又是一个卡了我好久好久好久的二分题 我真的不会二分啊,有没有大佬可以给我讲讲 我就是个憨憨 题目链接River Hopscotch 题目描述: Every year the cows hold an ...

  9. POJ 3258 River Hopscotch 经典二分

    点击打开链接 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6189   Accepted: ...

最新文章

  1. 2021第12届蓝桥杯省赛 -- 填空题:试题B:直线
  2. 2022斯坦福AI指数报告出炉!中国霸榜AI顶会,但引用量最低
  3. 如何结合因果与强化学习?看最新《因果强化学习:动机,概念,挑战与应用》报告,85页ppt...
  4. C# 调用C++ dll
  5. linux系列之-—04 自动删除n天前日志【转】
  6. javaweb上传文件_javaWeb中,如何通过CommonsFileUpload组件上传文件
  7. C# 多线程控制 通讯 和切换
  8. golang安装grpc,timeout问题
  9. ubuntu安装hadoop2.9.2
  10. 文字超过省略_纯CSS实现“文本溢出截断省略”的几种方法
  11. php数据库上线步骤,php连接数据库步骤
  12. dotnet new -i Microsoft.Maui.Templates
  13. 【POJ 3041】Asteroids【网络流 —— 最小点覆盖】
  14. foxmail6.5+易邮邮件服务器搭建局域网邮件收发系统(完整版包含测试)
  15. 网络安全----身份认证
  16. python的数组下标_python数组下标
  17. id: cannot find name for group ID 528
  18. Windbg调试命令详解(2)
  19. Matlab查看矩阵中包含的所有数字种类
  20. 程序员如何与产品撕逼

热门文章

  1. python 爬虫框架对比_用Python写爬虫,用什么方式、框架比较好?
  2. linux下打包rpm,打包rpm包 – 制作RPM包
  3. 微软短信服务器一直不可用,即时消息客户端功能不可用 - Outlook | Microsoft Docs
  4. SpringCloud:Eureka服务down状态日志解析
  5. 第一个android程序,qq农场助手
  6. 对于\n冲刷缓冲区,对Linux中fork()函数的理解
  7. 大数据-常用压缩方式总结
  8. 汇编语言DW、DB和DD的区别
  9. 推荐一个可保存网页的social bookmarking工具Furl
  10. 2021年全球陀螺测斜仪收入大约6百万美元,预计2028年达到7百万美元