"Recursion and recursion" princes place

Source: Internet
Author: User

"Recursion and recursion" princes place Title Description A long time ago, there was a mighty empire, its land in a square shape, shown in 2-2.

The country has a number of princes. As these princes had made illustrious exploits, the king was ready to give each of them a piece of land (a square in the squares). But the princes were very warlike, and when two princes were in the same row or column, they would go to war. If 2-3 is the land of the N=3, the shadow part indicates the position of the princes. The princes in the first two pictures could attack each other, and the third one could not.
The king naturally did not want to see his princes go to war with each other, causing the country to be troubled. Therefore, he hoped that by reasonable arrangement princes in the position, so that they can not attack between 22.
Now, given the square's edge length n, and the number of princes that need to be settled, ask you to find out the number of possible resettlement scenarios. (n≤l00,k≤2n2-2n+1)
Since the number of scenarios can be many, you only need to divide the output scheme number by the remainder of 504.

Enter only one row, two integers n and K, separated by a space. Outputs an integer that represents the remainder of the scheme number divided by 504. Sample input
2 2
Sample output
4
Tips

The four resettlement schemes are shown in 2-4. Note: The mirror and rotation conditions are different scenarios.

Analysis; violence can

Code:

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<ext/rope>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineVI vector<int>#definePII pair<int,int>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e2+Ten;Const intdis[][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;using namespace__gnu_cxx;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p;p=p*p;q>>=1;}returnF;}inta[maxn],n,m,cnt;voidDfsintPintNow ) {    if(now==m) {cnt= (cnt+1)%504;return;} if(p==2*n)return; DFS (P+1, now);  for(intI=1+abs (n-p); i<=2*n-1-abs (n-p); i++)    {        intJ;  for(j=1; j<p;j++)if(a[j]==i) Break; if(j==p) A[p]=i,dfs (p+1, now+1); }}intMain () {inti,j,k,t; scanf ("%d%d",&n,&m); DFS (1,0); printf ("%d\n", CNT); //System ("pause");    return 0;}

"Recursion and recursion" princes place

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.