[luoguP1373] 小a和uim之大逃离(DP)
Posted 蒟蒻zht的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[luoguP1373] 小a和uim之大逃离(DP)相关的知识,希望对你有一定的参考价值。
代码
#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)的主要内容,如果未能解决你的问题,请参考以下文章