zoukankan      html  css  js  c++  java
  • Cow Hopscotch

    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
    ",ans[n][m]);
        //system("pause");
        return 0;
    }
  • 相关阅读:
    第3、4、5讲
    .NetCore使用EF5操作Oracle,解决列自增序列绑定不生效的问题
    ASP.NET Core 之 Identity 入门(一)
    ORACLE NLS_DATE_FORMAT设置
    ORA12514遇到了怎么排查问题出在哪
    Oracle特殊字符查询语句
    ORA00821: Specified value of sga_target 3072M is too small, needs to be at least 12896M
    如何定位哪些SQL产生了大量的Redo日志
    Oracle定位对阻塞的对象或锁信息
    Oracle Undo和Redo的关系,区别及相关查询
  • 原文地址:https://www.cnblogs.com/dyzll/p/5775569.html
Copyright © 2011-2022 走看看