Codeforces 300D Painting Square __codeforces

Source: Internet
Author: User
the a surrounded is black by n rows of n columns of small lattice box, each can choose a square that has been surrounded by the black box will be a row of its one line of black requirements of the partition is also square, ask how many different coating K can be painted train of Thought because it can only be divided into squares, so it must be the most intermediate row and the middle column each time, then you can apply the number of times is constantly on N minus one divided by 2 to see how many layers, as for the answer to use DP calculation, from small to large, first turn to twice times, and then up and down into twice times, ans[i][j]= (ans[i ][j]+ (Temp[k]*temp[j-1-k]) (%mod)%mod,ans[i][j] means that the coating I layer has been coated with the number of J, Temp[k] means that the upper and lower half of the number of ways to apply K, temp[j]= (temp[j]+ (ans[i) [K]*ans[i][j-k])%mod, this is to do the extension of the left,%mod, the right tu j-k times, the total spread of the J, the last ans[layer][k] is the answer Code
 #include <cstdio> #define MOD 7340033 long long ans[31][1001],temp[1001]; int main () {L
    Ong Long q,n,k,cnt;
    Ans[0][0]=1;
    Temp[0]=1;
        For (long long i=1;i<=30;i++) {ans[i][0]=1; For (long long j=1;j<=1000;j++) for (long Long k=0;k<j;k++) ans[i][j]= (ans[i][j]+ (temp[k]*
        TEMP[J-1-K])%mod)%mod;
        For (long long j=1;j<=1000;j++) temp[j]=0;
        Temp[0]=1; For (long long j=1;j<=1000;j++) for (long Long k=0;k<=j;k++) temp[j]= (temp[j]+ (ans[i][k]*a
    NS[I][J-K])%mod)%mod;
    } scanf ("%i64d", &q);
        For (long long i=0;i<q;i++) {scanf ("%i64d%i64d", &n,&k);
        cnt=0;
            while ((n%2) &&n>1) {cnt++;
        n/=2;
    printf ("%i64d\n", Ans[cnt][k]);
return 0; }

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.