Editorial for Xây nhà
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của RR
{$R-,Q-} const FINP=''; FOUT=''; MAXN=1001; oo=12051987; var f1,f2:text; d:array[-1..MAXN,-1..MAXN] of int64; m,n:longint; procedure openF; begin assign(f1,FINP); reset(f1); assign(f2,FOUT); rewrite(f2); end; procedure closeF; begin close(f1); close(f2); end; procedure solve; var kq,i,j:longint; begin d[0,0]:=1; for i:=0 to m do for j:=0 to n do if (i>0) or (j>0) then d[i,j]:=(d[i-1,j]+d[i,j-1]) mod oo; kq:=0; for i:=1 to m do for j:=1 to n do kq:=(kq+((((m-i+1)*(n-j+1)) mod oo)*d[(i-1) div 2,(j-1) div 2]) mod oo) mod oo; writeln(f2,kq); end; begin openF; readln(f1,m,n); solve; closeF; end.
Code mẫu của hieult
#include <cstdio> //#include <algorithm> //#include <vector> //#include <conio.h> #define du 12051987 int C[1003][1003]; int min(int a,int b) { if(a<b) return a; return b; } int main() { for(int i = 0;i<=1001;i++) for(int j = 0;j<=1001;j++) C[i][j] = 0; for(int i = 0;i<=1001;i++) { C[0][i] = 1; for(int j = 1;j<=i;j++) C[j][i] = (C[j][i-1]+C[j-1][i-1])%du; } //for(int i = 1;i<=5;i++) // for(int j = 0;j<=i;j++) // printf("%d %d %d\n",j,i,C[j][i]); int n,m,kq=0,a,b; scanf("%d %d",&n,&m); for(int i = 1;i<2*n;i++) for(int j = 1;j<2*m;j++) { a = min(i,2*n-i); b = min(j,2*m-j); a = (a+1)/2; b = (b+1)/2; kq = (kq+C[a][a+b]-1)%du; } printf("%d",kq); // getch(); }
Comments