码迷,mamicode.com
首页 > 其他好文 > 详细

[luoguP1373] 小a和uim之大逃离(DP)

时间:2017-06-25 17:50:39      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:html   www   efi   getchar   stream   htm   etc   tchar   target   

传送门

 

题解

 

代码

#include <cstdio>
#include <iostream>
#define N 802
#define mod 1000000007

int n, m, p, ans;
int a[N][N], f[N][N][16][2];

inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch == ‘-‘) f = -1;
	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - ‘0‘;
	return x * f;
}

int main()
{
	int i, j, k;
	n = read();
	m = read();
	p = read() + 1;
	for(i = 1; i <= n; i++)
		for(j = 1; j <= m; j++)
			f[i][j][(a[i][j] = read()) % p][0] = 1;
	for(i = 1; i <= n; i++)
		for(j = 1; j <= m; j++)
		{
			for(k = 0; k < p; k++)
			{
				f[i + 1][j][(k + a[i + 1][j]) % p][0] = (f[i + 1][j][(k + a[i + 1][j]) % p][0] + f[i][j][k][1]) % mod;
				f[i + 1][j][(k - a[i + 1][j] + p) % p][1] = (f[i + 1][j][(k - a[i + 1][j] + p) % p][1] + f[i][j][k][0]) % mod;
				f[i][j + 1][(k + a[i][j + 1]) % p][0] = (f[i][j + 1][(k + a[i][j + 1]) % p][0] + f[i][j][k][1]) % mod;
				f[i][j + 1][(k - a[i][j + 1] + p) % p][1] = (f[i][j + 1][(k - a[i][j + 1] + p) % p][1] + f[i][j][k][0]) % mod;
			}
			ans = (ans + f[i][j][0][1]) % mod;
		}
	printf("%d\n", ans);
	return 0;
}

  

[luoguP1373] 小a和uim之大逃离(DP)

标签:html   www   efi   getchar   stream   htm   etc   tchar   target   

原文地址:http://www.cnblogs.com/zhenghaotian/p/7077205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!