COCI2018-2019#6 Mobitel

直接做是 $O(rsn)$ 的,显然会炸。

考虑反着做,$f[i][j][k]$ 表示 $(i,j)$ 走出去还至少要当前价值为 $k$。

转移枚举前一个,向上取整。

打表发现,对于 $1\le n\le 10^6$,$k$ 的有效个数最多只有 $2\times 10^3$ 个左右。故映射一下即可。

还有要滚动数组,不然空间会炸。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define maxn 1000005
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
inline void read(int &x){
int f=1;x=0;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
x*=f;
}
namespace Debug{
Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
int vis[maxn],id[maxn],cnt,g[maxn];
const int base=1e6;
const int mod=1e9+7;
inline void add(int &x,int y) {
if (x+y>mod) x=x-mod+y;else x+=y;
}
inline void dfs(int x) {
int l,r;
if (!vis[x]) vis[x]=1;
else return ;
for (l=1;l<=x;l++) {
r=min(x,(x/(x/l)));
dfs((x+l-1)/l);
dfs((x+r-1)/r);
l=r;
}
}
int r,s;
int f[2][305][2005],a[305][305];
signed main(void){
// freopen("1.in","r",stdin);
int i,j,k,sum=0,n,tmp,pre,x;
read(r);read(s);read(n);
dfs(n);
for (i=0;i<=n;i++) if (vis[i]) id[i]=++cnt,g[cnt]=i;
for (i=1;i<=r;i++) for (j=1;j<=s;j++) read(a[i][j]);
f[r&1][s+1][id[n]]=1;
for (i=r;i>=1;i--) {
tmp=i&1,pre=tmp^1;
if (i^r) memset(f[tmp],0,sizeof(f[tmp]));
for (j=s;j>=1;j--) {
x=a[i][j];
for (k=cnt;k>=1;k--) {
add(f[tmp][j][id[(g[k]+x-1)/x]],f[pre][j][k]);
add(f[tmp][j][id[(g[k]+x-1)/x]],f[tmp][j+1][k]);
// if (f[pre][j][k]) gdb(i+1,j,k,f[pre][j][k]);
// if (f[tmp][j+1][k]) gdb(i,j+1,k,f[tmp][j+1][k]);
}
}
}
printf("%d",f[1][1][1]);
return 0;
}