T685884 连词成句

· · 个人记录

观察到 nmk\le28,k|nm.

所以 k\le5 ,设答案为 ans 分类讨论。

k=5

## $k=4 ## $k=3 当 $nm=3,ans=1$. 当 $nm=6,ans=3$. ![](https://cdn.luogu.com.cn/upload/image_hosting/j6xmffx2.png) 当 $nm=9,ans=10$. ![](https://cdn.luogu.com.cn/upload/image_hosting/0gc617tl.png) ## $k=2

明显是一道状态压缩 dp 题目。

所以可以直接完成。

k=1

因为只能一个一个放。

ans=1
#include <cstring>
#include <iostream>
using namespace std;
const int N = 8, M = 1 << N;
typedef long long ll;
int n, m, k, T;
ll dp[N][M];
bool st[M];
int main() {
    cin >> T;
    while (T--) {
        cin >> n >> m >> k;
        if (n > m)swap(n, m);
        if (k == 5) {
            cout << 1 << endl;
        } else if (k == 4) {
            cout << 1 << endl;
        } else if (k == 3) {
            if (n == 2 && m == 3) {
                cout << 3 << endl;
            } else if (n == 3 && m == 3) {
                cout << 10 << endl;
            } else {
                cout << 1 << endl;
            }
        } else if (k == 1) {
            cout << 1 << endl;
        } else {
            if (n == 1) {
                cout << 1 << endl;
                continue;
            }
            if (k != 2)continue;
            for (int i = 0; i < 1 << n; i++) {
                int cnt = 0;
                st[i] = 1;
                for (int j = 0; j < n; j++) {
                    if (i >> j & 1) {
                        if (cnt & 1) {
                            st[i] = 0;
                        }
                        cnt = 0;
                    } else {
                        cnt++;
                    }
                }
                if (cnt & 1) {
                    st[i] = 0;
                }
            }
            memset(dp, 0, sizeof dp);
            dp[0][0] = 1;
            for (int i = 1; i <= m; i++) {
                for (int j = 0; j < 1 << n; j++) {
                    for (int k = 0; k < 1 << n; k++) {
                        if ((j & k) == 0 && st[j | k]) {
                            dp[i][j] += dp[i - 1][k];
                        }
                    }
                }
            }
            cout << dp[m][0] << endl;
        }

    }
    return 0;
}