Chessboard(HDUOJ_5100)

Problem Description

Consider the problem of tiling an n×n chessboard by polyomino pieces that are k×1 in size; Every one of the k pieces of each polyomino tile must align exactly with one of the chessboard squares. Your task is to figure out the maximum number of chessboard squares tiled.

Input

There are multiple test cases in the input file.
First line contain the number of cases T (T≤10000).
In the next T lines contain T cases , Each case has two integers n and k. (1≤n,k≤100)

Output

Print the maximum number of chessboard squares tiled.

Sample Input

2
6 3
5 3

Sample Output

36
24

QAQ巨巨教的方法,学会骨牌的完美覆盖这种题就没什么问题了~组合数学的内容~推荐Richard A.Brualdi 的《Introductory Combinatorics Fifth Edition》,中文版说实话有的地方看不懂,可能我理解力有问题==

代码

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int t,n,k;
    scanf("%d",&t);
    while(t--)
    {
        int a[101][101]={0};
        int flag[101]={0};
        int r=0,c;
        scanf("%d%d",&n,&k);
        if(n<k)
        {
            printf("0\n");
            continue;
        }
        for(int i=0;i<n;i++)
        {
            c=r;
            r=(r-1==-1?k-1:r-1);
            for(int j=0;j<n;j++)
            {
   // a[i][j]=c;
   // cout<<a[i][j]<<' ';
                flag[c]++;
                c=(c+1)%k;
            }
   // cout<<endl;
        }
        int ans=9999999;
        for(int i=0;i<k;i++)
            if(flag[i]<ans)
                ans=flag[i];
        printf("%d\n",ans*k);
    }
    return 0;
}

你可能感兴趣的:(Chessboard(HDUOJ_5100))