Links: Https://www.nowcoder.com/acm/contest/74/F
Source: Niu Ke Net
Title Description Demacia is a strong, law-abiding country, with outstanding meritorious history of the military. This place attaches great importance to the ideology of justice, honor and responsibility, and the people here are very proud of it. One day they wanted to sanction the evil bilgewater, so they sent their best fighters. As a result bilgewater the territory was too small, only a length of n wide for m amounted to n*m block of land, some of which were labeled 0 as mountains or deep-sea lakes, where heroes could not stand, only the land marked 1 could accommodate a hero. The heroes of Demacia have a characteristic of fighting, and they don't want their teammates to stand beside themselves and look ambiguous. Can you tell me how many ways to arrange Demacia heroes? Input Description:
Input contains multiple sets of test data;
The first row of each group of data contains 2 integers n and m (n <=, M <= 12), separated by a space;
The next n rows, the number of M per line, represent N*m's bilgewater territory.
Output Description:
Outputting an integer n represents the method for arranging the application.
(The answer is taken from the film 100000000)
Example 1 input
3 31 1 10 1 11 0 0
Output
24
Exercises
Pressure $dp$.
$DP [i][j][k]$ represents to the $i$ layer, the $j$ person is placed, and the placement status of the $i$ layer is the number of scenarios for $k$.
There are many optimizations that can be done without optimization.
#include <bits/stdc++.h>using namespace Std;int N, m;int a[20][20];int h[20];long long Dp[15][80][4100];long long m OD = 100000000ll;int cnt[4100], error[4100];int limit = 75;int lowbit (int x) {return x & (x);} void Init () {for (int i = 1; i < (1 <<); i + +) {Cnt[i] = Cnt[i-lowbit (i)] + 1; } for (int i = 0; i < (1 <<); i + +) {for (int j = 0; J < N; j + +) {int A = i & (1 << j) ; int B = i & (1 << (j + 1)); if (A && B) error[i] = 1; }}}int Main () {init (); while (~SCANF ("%d%d", &n, &m)) {for (int i = 1; I <= n; i + +) {H[i] = 0; for (int j = 0; J < m; J + +) {scanf ("%d", &a[i][j]); H[i] = h[i] * 2 + a[i][j]; }} Dp[0][0][0] = 1; for (int i = 1; I <= n; i + +) {for (int num = 0; num <= limit; num + +) {for (int. now = 0; now < (1 < ;< m); Now + +) {Dp[i][num][now] = 0; if (Error[now]) continue; if (now | h[i])! = H[i]) continue; if (Num-cnt[now] < 0) continue; for (int pre = 0; pre < (1 << m); pre + +) {if (Error[now]) continue; if (pre & now) continue; Dp[i][num][now] = (Dp[i][num][now] + dp[i-1][num-cnt[now]][pre])% MoD; }}}} long long ans = 0; for (int num = 0; num <= limit, num + +) {for (int now = 0; now < (1 << m); now + +) {ans = (ans + d P[n][num][now])% MoD; }} printf ("%lld\n", ans); } return 0;}
2018 National multi-school algorithm winter training Camp Practice Competition (second session) F-de Marcia Long live