6311. Mobitel

6311. Mobitel 
(File IO): input:mobitel.in output:mobitel.out

Time Limits: 6000 ms  Memory Limits: 65536 KB  Detailed Limits  

Description

给定一个 r 行 s 列的矩阵,每个格子里都有一个正整数。
问如果从左上角走到右下角,且每次只能向右或向下走到相邻格子,那么使得路径上所有数的乘积不小于 n 的路径有多少条?
由于答案可能很大,所以请输出答案对 10^9+7 取模的结果。

Input

第一行三个正整数 r,s,n。
接下来 r 行,每行 s 个正整数,依次表示矩阵每一行的数。

Output

一行一个整数表示答案。

Sample Input

Sample 1:
2 3 200
2 3 4
5 6 7

Sample 2:
3 3 90
2 1 1
45 1 1
1 1 1

Sample 3:
2 5 3000
1 2 3 4 5
6 7 8 9 10
 

Sample Output

Sample 1:
2

Sample 2:
3

Sample 3:
3

Data Constraint

对于 20% 的数据,矩阵中的数不超过 10;
对于 50% 的数据,1<=r,s<=100;
对于 100% 的数据,1<=r,s<=300,1<=n<=10^6,矩阵中的数不超过10^6。

Source / Author: COCI 2018/2019 Round #6 mobitel

 

题解:

设f[i][j][k]为走到ij , 乘积为k的方案数。

空间承受不了。

我们设k = (n-1) / x , 表示当前乘积为x后 , 还能乘多少。

比如当n为20 , (n-1)=19 。当x为5和6时 , k都为3 , 但是他们“本质”上相同,因为5、6两个数当*4都会爆。

要推广到多个数也简单 , 因为有定理\left \lfloor {\tfrac{a}{bc}} \right \rfloor = \left \lfloor {\tfrac{ \left \lfloor \tfrac{a}{b} \right \rfloor}{c}} \right \rfloor

发现k只有2倍根号种取值 , 编一下号 , dp就行。

赋上定理证明 : 

 

记 a = (x * c + y) * b + z

其中 0 <= y < c, 0 <= z < b

可得 a = x * b * c + y * b + z

[[a / b] / c] = [(x * c + y) / c] = x
[a / (b * c)] = x + (y * b + z) / (b * c)

假设 [[a/b]/c] != [a/(b*c)]

则有 y * b + z >= b * c

等同 z >= (c - y) * b

因为 y < c, 所以c - y >= 1,

又因 z < b, 所以上式不成立

故原命题得证。

 

#include
#include
#include
#define mem(a,b) memset(a,b,sizeof(a))
#define mcy(a,b) memcpy(a,b,sizeof(a))
#define N 310
#define maxn (ll)(1e6)
#define SQ 3001
#define ll long long
#define re register
#define inf 2147483647
#define mod (ll)(1e9+7)
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
using namespace std;

template 
T in(T &x)
{
	char ch(0);T f=0; x=0;
	while(ch < '0' || ch > '9') ch = getchar() , f |= ch == '-';
	while(ch>='0' && ch<='9')  x = (x<<1) + (x<<3) + ch - '0' , ch = getchar();
	return f ? (x = -x) : x;
}

int LIMIT,m,n;
int a[N][N], g[2][N][SQ];
int st[SQ],cnt,ff[maxn];

void dp()
{
	mem(st,cnt=0);
	for(int i=1;i<=LIMIT;i++) ((LIMIT-1) / i!=st[cnt]) && (st[++cnt] = (LIMIT-1)/i ,ff[st[cnt]]=cnt);
	
	g[0][1][ff[(LIMIT-1)/a[1][1]]]=1;
	for(int i=1;i<=n; i++ , (i<=n) && mem(g[i&1],0))
	  for(int j=1;j<=m;j++) 
	    for(int k=1;k<=cnt;k++)
		  if(g[~i&1][j][k])
		  	  i

 

你可能感兴趣的:(dp,分块,根号算法)