bzoj3939 [Usaco2015 Feb]Cow Hopscotch

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3939

【题解】

f[i][j] = s[i-1][j-1] - sum[a[i][j]]

用cdq分治来处理横坐标,先处理上面的dp值,再讨论上面部分对下面的贡献,然后分治处理下面的dp值即可。

如果加了快读好像排bzoj rk1?

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 7e5 + 10, N = 750 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

int n, m, K;
int a[N][N], t[M], f[N][N];

inline void solve(int l, int r) {
    if(l == r) return ;
    int mid = l+r>>1, sum = 0;
    solve(l, mid);
    for (int j=1; j<=m; ++j) {
        for (int i=mid+1; i<=r; ++i) {
            f[i][j] += (sum - t[a[i][j]] + mod) % mod;
            if(f[i][j] >= mod) f[i][j] -= mod;
        }
        for (int i=l; i<=mid; ++i) {
            sum = sum + f[i][j];
            if(sum >= mod) sum -= mod;
            t[a[i][j]] = t[a[i][j]] + f[i][j];
            if(t[a[i][j]] >= mod) t[a[i][j]] -= mod;
        }
    }
    for (int j=1; j<=m; ++j)
        for (int i=l; i<=mid; ++i)
            t[a[i][j]] = 0;
    solve(mid+1, r);
}

int main() {
    cin >> n >> m >> K;
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=m; ++j) scanf("%d", &a[i][j]);
    f[1][1] = 1;
    solve(1, n);
    cout << f[n][m];
    return 0;
}

时间: 2024-10-11 17:27:57

bzoj3939 [Usaco2015 Feb]Cow Hopscotch的相关文章

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

题目描述 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

【Usaco2015 FEB】Cow Hopscotch (Gold)

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 surp

洛谷P3120 [USACO15FEB]Cow Hopscotch

题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John&apos;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 thi

bzoj3943[Usaco2015 Feb]SuperBull*

bzoj3943[Usaco2015 Feb]SuperBull 题意: n头牛进行锦标赛,每场比赛的好看程度是两头牛的编号异或和,并总有一方被淘汰.求安排比赛(可以决定比赛胜负)可以得到的最大总好看程度是多少.n≤2000 题解: 先求出牛两两之间的异或和,然后发现可以把比赛看做连边,且共有n-1场比赛,所以求最大生成树就行了.神犇们用的都是Prim,蒟蒻不会,用Kruscal结果时间排倒数. 代码: 1 #include <cstdio> 2 #include <cstring>

bzoj3942: [Usaco2015 Feb]Censoring

AC自动机.嗯bzoj3940弱化版.水过去了(跑的慢啊QAQ.想了想可以用hash写.挖坑 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define clr(x,c) memset

[BZOJ1697][Usaco2007 Feb]Cow Sorting牛排序

1697: [Usaco2007 Feb]Cow Sorting牛排序 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 712  Solved: 416 [Submit][Status][Discuss] Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾气大的牛有可能会捣乱,JOHN想把牛按脾气的大小排序.每一头牛的脾气都是一个在1到100,000之间的整数并且没有两头牛的脾气值相同.

[BZOJ] 1631: [Usaco2007 Feb]Cow Party

1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 866  Solved: 624[Submit][Status][Discuss] Description 农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前去X牛棚参加派对还是返回住所,她们都采用了用时最

BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ---------------------------------------------------------------------------------- #include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; ++i) #define clr(x

3301: [USACO2011 Feb] Cow Line

3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit][Status][Discuss] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer Joh