【luogu P1373 小a和uim之大逃离】 题解

题目链接:https://www.luogu.org/problemnew/show/P1373

想不出来状态

看了一眼题解状态明白了

dp[i][j][h][1/0] 表示在i,j点差值为h是小A还是uim移动的

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 801;
const int mod = 1e9+7;
ll dp[maxn][maxn][31][2], m, n, a[maxn][maxn], ans, k;
void init()
{
	for(ll i = 1; i <= n; i++)	
		for(ll j = 1; j <= m; j++) dp[i][j][a[i][j]%k][0] = 1;//小A 
}
int main()
{
	cin>>n>>m>>k;
	k++;
	for(ll i = 1; i <= n; i++)
		for(ll j = 1; j <= m; j++) cin>>a[i][j];
	init();
	for(ll i = 1; i <= n; i++)
		for(ll j = 1; j <= m; j++)
			for(ll o = 0; o < k; o++)
			{
				dp[i][j][o][0] = (dp[i-1][j][(o-a[i][j]+k)%k][1] + dp[i][j][o][0])%mod;
				dp[i][j][o][1] = (dp[i-1][j][(o+a[i][j])%k][0] + dp[i][j][o][1])%mod;
				dp[i][j][o][1] = (dp[i][j-1][(o+a[i][j])%k][0] + dp[i][j][o][1])%mod;
				dp[i][j][o][0] = (dp[i][j-1][(o-a[i][j]+k)%k][1] + dp[i][j][o][0])%mod;
			}
	for(ll i = 1; i <= n; i++)
		for(ll j = 1; j <= m; j++)
		ans = (ans + dp[i][j][0][1])%mod;
	cout<<ans;
	return 0;
}
posted @ 2018-10-18 14:22  Misaka_Azusa  阅读(109)  评论(0编辑  收藏  举报
Live2D