Test instructions: The number of scenarios in which the n*m placed two attacks against each other
Separate discussion rows and columns two diagonal lines
A sum-up
Can be simplified after the calculation of
////main.cpp//uva11538////Created by Candy on 24/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;inline ll Read () {CharC=getchar (); ll x=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;} ll N,m;intMainintargcConst Char*argv[]) { while((n=read ())) {m=read (); if(n>m) swap (N,M); ll ans=m* (m+n-2) *n+2*n* (n1)*(3*m-n-1)/3; printf ("%lld\n", ans); } return 0;}
Uva-11401triangle counting |
Test instructions: 1 to n select three different number of programs that make up a triangle
Consider the triangle with I as the largest edge, i-y<z<i
(i-1) * (i-2)/2 minus the remaining y==z, i/2+1....i-1 can be equal
////main.cpp//uva11401////Created by Candy on 24/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=1e6+5; typedefLong LongLl;inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;} ll F[n],n;voiddp () {f[3]=0; for(LL i=4; i<=1e6;i++) F[i]=f[i-1]+ ((I-1) * (I-2)/2-(I-1-i/2))/2;}intMainintargcConst Char*argv[]) {DP (); while((N=read ()) >=3) {printf ("%lld\n", F[n]); } return 0;}
Test instructions: N*m put K stone, the first row in the last row of the last column to have
No, it's good to ask for a combination number.
Binary enumeration sets, variable odd-negative pairs using the tolerant principle
////main.cpp//uva11806////Created by Candy on 24/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=505, mod=1000007; typedefLong LongLl;inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intT,n,m,k,f[n][n];voidinit () {f[0][0]=1; for(intI=1; i<= -; i++) {f[i][0]=f[i][i]=1; for(intj=1; j<i;j++) f[i][j]= (f[i-1][j]+f[i-1][j-1])%MOD; }}intMainintargcConst Char*argv[]) {init (); T=read ();intcas=0; while(t--) {cas++; N=read (); M=read (); k=read (); intans=0; for(ints=0; s< -; s++){ intb=0, r=n,c=m; if(s&1) R--, b++; if(s&2) R--, b++; if(s&4) C--, b++; if(s&8) C--, b++; if(b&1) ans= (ans-f[r*c][k]+mod)%MOD; ElseAns= (Ans+f[r*c][k])%MOD; } printf ("Case %d:%d\n", Cas,ans); } return 0;}
UVa counting method Exercise [3]