记录编号 160208 评测结果 AAAAAAAAAAAAAAA
题目名称 牛跳房子 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 1.088 s
提交时间 2015-04-24 17:36:45 内存使用 6.75 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
//#define USEFREAD
#ifdef USEFREAD
#define InputLen 5000000
char *ptr=(char *)malloc(InputLen);
#define getc() (*(ptr++))
#else
#define getc() (getchar())
#endif
#define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout))
template<class T>inline void getd(T &x){
	int ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')ch = getc(), neg = true;
	x = ch - '0';
	while(isdigit(ch = getc()))
		x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 752, maxk = 563000, mod = 1000000007;

int G[maxn][maxn], N, M, K, Sum, Col[maxk], F[maxn][maxn];

inline void Add(int &x, int d){x = (x + d) % mod;}

inline void init(){
	getd(N), getd(M), getd(K);
	int i, j;
	for(i = 0;i < N;++i)for(j = 0;j < M;++j)getd(G[i][j]);
}

void work(int L, int R){
	if(R - L == 1)return;
	int mid = L + R >> 1, i, j, *f;
	work(L, mid);
	for(i = 1;i < N;++i){
		for(j = L, f = F[i-1] + L;j < mid;++j, ++f){
			Add(Sum, *f);
			Add(Col[G[i-1][j]], *f);
		}
		for(j = mid, f = F[i] + mid;j < R;++j, ++f){
			Add(*f, Sum);
			Add(*f, mod - Col[G[i][j]]);
		}
	}
	Sum = 0;
	for(i = 0;i < N;++i)for(j = L;j < mid;++j)Col[G[i][j]] = 0;
	work(mid, R);
}

int main(){
	#ifdef DEBUG
	freopen("test.txt", "r", stdin);
	#else       
	SetFile(hopscotch);
	#endif
	#ifdef USEFREAD
	fread(ptr,1,InputLen,stdin);
	#endif
	
	init();
	**F = 1;
	work(0, M);
	printf("%d\n", F[N-1][M-1]);
	
#ifdef DEBUG
    printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
    return 0;
}