Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define f first
- #define s second
- #define pb push_back
- #define mp make_pair
- #define ll long long
- #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- using namespace std;
- const int INF = 1e9 + 10;
- const int MOD = 1e9 + 7;
- const int MOD2 = 1e9 + 9;
- const int MAXN = 2e6 + 10;
- int a[MAXN];
- int dp[12][110][3000];
- int cnt[22][22];
- void solve(){
- int n, m;
- cin >> n >> m;
- if (n > m)
- swap(n, m);
- dp[0][1][0] = 1;
- for (int j = 1; j <= m; j++){
- for (int i = 1; i <= n; i++){
- for (int mask = 0; mask < (1 << n); mask++){
- if ((mask >> (i - 1)) & 1){
- dp[i][j][mask ^ (1 << (i - 1))] += dp[i - 1][j][mask];
- if (dp[i][j][mask ^ (1 << (i - 1))] >= MOD){
- dp[i][j][mask ^ (1 << (i - 1))] -= MOD;
- }
- }
- else{
- dp[i][j][mask ^ (1 << (i - 1))] += dp[i - 1][j][mask];
- if (dp[i][j][mask ^ (1 << (i - 1))] >= MOD){
- dp[i][j][mask ^ (1 << (i - 1))] -= MOD;
- }
- if (i < n && ((mask >> i) & 1) == 0){
- dp[i][j][mask ^ (1 << i)] += dp[i - 1][j][mask];
- if (dp[i][j][mask ^ (1 << i)] >= MOD){
- dp[i][j][mask ^ (1 << i)] -= MOD;
- }
- }
- }
- }
- }
- for (int mask = 0; mask < (1 << n); mask++){
- dp[0][j + 1][mask] = dp[n][j][mask];
- }
- }
- cout << dp[n][m][0] << "\n";
- }
- int main() {
- IOS;
- int t = 1;
- //cin >> t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment