A Simple Problem itime limit:3000/1000ms (java/other) Memory limit:65535/32768k (Java/other) total submission (s): 70 Accepted Submission (s): 33font:times New Roman | Verdana | Georgiafont Size:←→problem Description Tell you the truth, ikids like to play chess, what chess he loves! But compared to playing chess, as a acmer, he prefers to study chess, because a lot of topics are involved in a variety of chess (ORZ), this is not, recently he was fascinated by the chess car, now let me tell you about the car in the rules of the board!
As a pawn after the queen, it can walk vertically, but also can walk sideways (in fact, Chinese chess car is the same.) Hahahah), but when it encounters a car in the same row, it likes to eat it, as shown.
R2, R3 on the conflict! This is not ikids hope!!! So, here's the question:
Given two integers n and K, representing N*n's chessboard, and K-cars, ask how many kinds of places you have, so that no two cars will appear as R2,R3 this situation! Input the first line to enter a T (t<=100000), which represents the number of test data groups.
For each group, enter two integers n,k; N*n's chessboard, K-car, n<=30,k <=n^2output for each set of data, the output Ans,ans is the number of places to display.
The data guarantee does not exceed unsigned long long int. Sample Input
81 12 43 14 14 24 34 44 5
Sample Output
109167296240
Combinatorial math, Ans=a (n,m) *c (n,m) n rows put K cars, N-column can also put K cars, the two placed multiplied by K!
Because the time to do this is over, so borrow the code from the link below
#include <iostream> #include <cstdio> #define ULL unsigned long longusing namespace std;const int maxn=35; ULL DP[MAXN][MAXN*MAXN]; ULL C (int n,int m) { if (n<m) return 0; ULL Ans=1; for (int i=0;i<m;i++) ans=ans* (ULL) (n-i)/(ULL) (i+1); return ans;} ULL A (int n,int m) { if (n<m) return 0; ULL Ans=1; for (int i=0;i<m;i++) ans*= (ULL) (n-i); return ans;} ULL Fuck (int n,int k) { if (Dp[n][k]) return dp[n][k]; Return Dp[n][k]=a (n,k) *c (n,k);} int main () { //freopen ("In.txt", "R", stdin); int n,k,t; scanf ("%d", &t); while (t--) { scanf ("%d%d", &n,&k); printf ("%i64u\n", Fuck (N,k)); printf ("%i64u\n", A (N,k)); printf ("%i64u\n", C (N,k)); } return 0;}
Hunan University of Technology Innovation Laboratory 2015 Freshman (i) 1001 (re-opened)