Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- bool bit(ll var, int pos) {
- return ((var >> pos) & 1);
- }
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int n, m;
- fin >> n >> m;
- vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(m + 1, vector<ll>(1 << n + 1)));
- for (int j = 0; j < m; j++) {
- for (int i = 0; i < (1 << n + 1); i++) dp[j][0][i] = 1;
- }
- for (int i = 0; i < (1 << 1); i++) dp[0][1][i] = 1;
- for (int j = 0; j < m; j++) {
- for (int i = 0; i < n; i++) {
- for (int prof = 0; prof < (1 << n + 1); prof++) {
- if (i == n - 1) {
- dp[0][j + 1][((prof << 1) & ~(1 << n+1))] += dp[i][j][prof];
- dp[0][j + 1][((prof << 1) & ~(1 << n + 1)) | 1] += dp[i][j][prof];
- }
- else {
- int sum = bit(prof, i - 1) + bit(prof, i) + bit(prof, i + 1);
- if (sum + 1 != 4) dp[i + 1][j][(prof | (1 << i))] += dp[i][j][prof];
- if (sum != 0) dp[i + 1][j][(prof & (~(1 << i)))] += dp[i][j][prof];
- }
- }
- }
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment