Topic Link Click Open link
Test instructions
n Row m column grid put K stones. How many ways are there? Requires the first row, the first column, the last row, and the last column must have a stone.
Ideas:
1. Expansion using the principle of tolerance
Suppose there are three sets of S and another three set a B C, which is not a, B, or C, but belongs to the complete set of S elements, an odd number is reduced; an even number is added.
Here are the four cases where S is the empty set a, B, C, and D, respectively, representing the ranks:
Aubucud = | a| + | b| + | c| + | d| - | ab| - | bc| - | ac| - | ad| - | bd| - | cd| + | abc| + | abd| + | acd| + | bcd| - | abcd|
If you are in collection A or B, it is equivalent to one less row, and if you are in collection C or D, it is equivalent to a column missing.
Assuming the last row row, col column, the method number is C (row*col,k)
2. Use binary to represent four situations
3. Number of calculated combinations: C (n+1,k+1) =c (n,k+1) + (n,k)
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include < Algorithm>using namespace Std;typedef long long LL; #define MOD 1000007#define MAX 510int c[max][max];void C ()//calculation combination number {m Emset (C,0,sizeof (c)); c[0][0]=1;for (int i=0;i<=500;i++) {c[i][0]=c[i][i]=1;for (int j=1;j<i;j++) c[i][j]= (c[ I-1][j]%mod+c[i-1][j-1]%mod)%mod;}} int main () { int t,ca=1; scanf ("%d", &t); while (t--) { C (); int m,n,k; scanf ("%d%d%d", &m,&n,&k); int sum=0; for (int i=0;i<16;i++) { int count=0,row=m,col=n; if (i&1) { row--; count++; } if (i&2) { row--; count++; } if (i&4) { col--; count++; } if (i&8) { col--; count++; } if (count&1) sum= (sum+mod-c[row*col][k])%mod;//odd number of minus else sum= (sum+c[row*col][k])%mod;//even number of Add}printf ("Case%d:%d\n", ca++,sum); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 11806-cheerleaders (Repulsion principle + binary)