bzoj1087: [SCOI2005] Non-aggression king

Source: Internet
Author: User

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]) &AMP;&A MP;K+NUM[T]&LT;=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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.