CodeForces 273D|Dima and Figure|动态规划

N*M( 150 )的棋盘有多少个连通块是凸的。

绕了好几个弯之后终于搞定了。。
f[i][j][k][l] 表示现在到了第i行,当前连通块占用j~k列,状态为l。
考虑一个连通块,我们用一条线扫过去,发现可能的情况只有覆盖区域:变小,变大,左移,右移(没有限定区域大小)。所以l就表示这4种情况。
那么左右边界只可能有:一直扩张,一直收缩,或者先扩张再收缩。
那么转移就好搞了。
转移的时候要搞个前缀和。。

#include <cstdio>
#include <cstring>
#define FOR(i,j,k) for(i=j;i<=k;++i)
#define ROF(i,j,k) for(i=j;i>=k;--i)
typedef long long ll;
const int N = 155, mod = 1000000007;
ll f[2][N][N][4], g[N][N];
ll M(ll &a) { return a > mod ? a %= mod : a; }
int main() {
    int n, m, i, j, k, t, n0, n1; ll ans = 0;
    scanf("%d%d", &n, &m);
    FOR(i,1,n) {
        n0 = i & 1; n1 = (i + 1) & 1;
        FOR(j,1,m) FOR(k,j,m) {
            M(++f[n0][j][k][0]);
            FOR(t,0,3) M(ans += f[n0][j][k][t]);
        }
        // Case 0
        FOR(j,1,m) FOR(k,j,m) M(g[j][k] = g[j][k - 1] + f[n0][j][k][0]);
        ROF(k,m,1) ROF(j,k,1) f[n1][j][k][0] = M(g[j][k] += g[j + 1][k]);
        // Case 1
        FOR(j,1,m) {
            FOR(k,j,m) M(g[j][k] = g[j - 1][k] + f[n0][j][k][1] + f[n0][j - 1][k][0]);
            FOR(k,j,m) M(f[n1][j][k][1] = f[n1][j][k - 1][1] + g[j][k]);
        }
        // Case 2
        ROF(k,m,1) {
            ROF(j,k,1) M(g[j][k] = g[j][k + 1] + f[n0][j][k][2] + f[n0][j][k + 1][0]);
            ROF(j,k,1) f[n1][j][k][2] = (f[n1][j + 1][k][2] + g[j][k]) % mod;
        }
        // Case 3
        FOR(j,1,m) FOR(k,j,m)
            M(g[j][k] = f[n0][j][k][3] + f[n0][j - 1][k][2] + f[n0][j][k + 1][1] + f[n0][j - 1][k + 1][0]);
        FOR(j,1,m) ROF(k,m,j) M(g[j][k] += g[j][k + 1]);
        FOR(j,1,m) FOR(k,j,m) M(g[j][k] += g[j - 1][k]);
        FOR(j,1,m) FOR(k,j,m) f[n1][j][k][3] = g[j][k];
    }
    printf("%I64d", ans);
    return 0;
}

D. Dima and Figure

Dima loves making pictures on a piece of squared paper. And yet more than that Dima loves the pictures that depict one of his favorite figures.

A piece of squared paper of size n × m is represented by a table, consisting of n rows and m columns. All squares are white on blank squared paper. Dima defines a picture as an image on a blank piece of paper, obtained by painting some squares black.

The picture portrays one of Dima’s favorite figures, if the following conditions hold:

The picture contains at least one painted cell;
All painted cells form a connected set, that is, you can get from any painted cell to any other one (you can move from one cell to a side-adjacent one);
The minimum number of moves needed to go from the painted cell at coordinates (x1, y1) to the painted cell at coordinates (x2, y2), moving only through the colored cells, equals |x1 - x2| + |y1 - y2|.
Now Dima is wondering: how many paintings are on an n × m piece of paper, that depict one of his favorite figures? Count this number modulo 1000000007 (109 + 7).

Input

The first line contains two integers n and m — the sizes of the piece of paper (1 ≤ n, m ≤ 150).

Output

In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7).

Examples

input

2 2

output

13

input

3 4

output

571
// 0LR 1RR 2LL 3RL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值