比赛 |
20150424 |
评测结果 |
AAAAAAAAATTTEEE |
题目名称 |
牛跳房子 |
最终得分 |
60 |
用户昵称 |
Asm.Def |
运行时间 |
7.834 s |
代码语言 |
C++ |
内存使用 |
2.32 MiB |
提交时间 |
2015-04-24 11:41:19 |
显示代码纯文本
#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 mod = 1000000007, maxk = 562505, maxn = 752;
int N, M, K, G[maxn][maxn];
#include <map>
struct Fenwick{
int A[maxn];
Fenwick(){memset(A, 0, sizeof(A));}
inline void Add(int i, int x){
while(i <= M){
A[i] = (A[i] + x) % mod;
i += (i & -i);
}
}
inline int Sum(int i){
int Ans = 0;
while(i){
Ans = (Ans + A[i]) % mod;
i ^= (i & -i);
}
return Ans;
}
};
map<int, Fenwick> Map[maxn];
inline void Add(int x, int y, int d){
int c = G[x][y];
while(x <= N){
Map[x][c].Add(y, d);
Map[x][0].Add(y, d);
x += (x & -x);
}
}
inline int Sum(int x, int y){
if(x == 1 || y == 1)return 0;
int c = G[x][y], Ans = 0;--x, --y;
while(x){
Ans = (Ans + Map[x][0].Sum(y)) % mod;
Ans = (Ans + mod - Map[x][c].Sum(y)) % mod;
x ^= (x & -x);
}
return Ans;
}
inline void work(){
getd(N), getd(M), getd(K);
int i, j, Ans = 0;
for(i = 1;i <= N;++i)for(j = 1;j <= M;++j)getd(G[i][j]);
Add(1, 1, 1);
for(i = 2;i <= N;++i)for(j = 2;j <= M;++j)
Add(i, j, Ans = Sum(i, j));
printf("%d\n", Ans);
}
int main(){
#ifdef DEBUG
freopen("test.txt", "r", stdin);
#else
SetFile(hopscotch);
#endif
#ifdef USEFREAD
fread(ptr,1,InputLen,stdin);
#endif
work();
#ifdef DEBUG
printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}