Bare-like pressure dp.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (i,n) for (int i=1;i<=n;i++) #define CLR (x,c) memset (x,c,sizeof (x)) #define LL Long Long #define REP (I,s, T) for (int i=s;i<=t;i++) int n,m,state[1000],num[1000];ll dp[15][1<<11][100];bool check (int x,int y) {if (x & (y<<1)) | | (x& (y>>1)) | | (X&y)) return False;return true;} BOOL PD (int x) {if (x& (x<<1)) | | (x& (x>>1))) return False;return true;} int get (int x) {int ans=0;while (x) {if (x&1) ans++;x>>=1;} return ans;} void Init () {scanf ("%d%d", &n,&m); REP (i,0, (1<<n)-1) if (PD (i)) state[++state[0]]=i,num[state[0]]=get (i);//rep (I,state[0]) printf ("%d%d\n", State[i],num[i]);} void work () {CLR (dp,0); Rep (i,state[0]) dp[1][i][num[i]]=1; Rep (I,2,n) {rep (j,state[0]) Rep (k,0,m) if (Dp[i-1][j][k]) rep (t,state[0]) if (check (state[j],state[t]) &&A MP;K+NUM[T]<=M) dp[i][t][k+num[t]]+=dp[i-1][j][k];} LL Ans=0;rep (i,state[0]) ans+=dp[n][i][m];p rintf ("%lld\n", ans); int main () {init (); work (); return 0;}
1087: [SCOI2005] Non-aggression king time limit:10 Sec Memory limit:162 MB
submit:2779 solved:1638
[Submit] [Status] [Discuss] Description
Put K Kings in NxN's chessboard, so that they do not attack each other, there are many kinds of layout plan. The king could attack it up and down, and the upper left
Lower left bottom right upper right bottom eight directions near each one of the lattice, a total of 8 squares.
Input
Only one row, containing two numbers n,k (1 <=n <=9, 0 <= K <= n * N)
Output
Number of scenarios.
Sample Input3 2Sample Output -HINT Source [Submit] [Status] [Discuss]
bzoj1087: [SCOI2005] Non-aggression king