1020 Anniversary Cake

topic:

Description
Nahid Khaleh decided to invite "Shahr-e Ghashang" children attend her wedding anniversary. She wanted to prepare a known size of a square of chocolate cake. She asked everyone to be invited to determine the size of his / her desired piece of cake (it should be square). She knew Mr. Kavoosi does not waste any cake. She wondered if she could make a square cake of this size, it can meet all the requirements, and no waste.
Input
The first line of the input file contains an integer t (1≤t≤10), the number of test cases and each test case is the input data. Each row contains an integer of test s, i.e. the side of the cake, followed by an integer n (1≤n≤16), the number of blocks of the cake, followed by n integers (in the range of 1..10)) specified for each piece sides.
The output of
each test case should have an output line that contains a word KHOOOOB! Or HUTUTU! Depending on whether the cake can be cut into pieces of a particular size without any waste.
Sample input
2
. 4. 8. 3. 1. 1. 1. 1. 1. 1. 1
. 5. 3 2. 6. 3. 1. 1. 1
Sample Output
KHOOOOB!
HUTUTU!

#include <the iostream> the using namespace STD; int POS [ 100 ];                       // i th column with a POS [i] line int Cake [ 18 is ];                       // number of i-th cake int cake_num;
 int cake_size; BOOL the DFS ( int NUM) 
{ IF (NUM == cake_num) return to true ;        // cake run out return to true int MIN = 999 , index = - . 1 ;
     for ( int I = . 1

 






     
    ; I <= cake_size; I ++)       // find the minimum number of rows of columns expenses 
    {
         IF (MIN> POS [I]) 
        { 
            MIN = POS [I]; 
            index = I; 
        } 
    } 
    for ( int I = 10 ; I > = . 1 ; i--)          // enumeration each side 
    {
         IF (Cake [I] && + I MIN <= cake_size && index I + - . 1 <= cake_size)      // boundary tentative 
        {
             int In Flag = . 1 ;
             for (int J = index; J <I = index + - . 1 ; J ++)         // row subsequent enum 
            {
                 IF (POS [J]> MIN)            // greater expenses not listed then put here 
                { 
                    In Flag = 0 ;
                     BREAK ; 
                } 
            } 
            IF (In Flag!) Continue ; 
            cake [I] -;               // cake can be put down 
            for ( int J = index; J <I = index + - . 1 ; J ++) POS [J] + = I;
             IF (DFS(num + 1)) return true;
            cake[i]++;            //放错地方了
            for (int j = index; j <= index + i - 1; j++) pos[j] -= i;
        }
    }
    return false;
}

int main()
{
    int t, edge, sum;
    cin >> t;
    while (t--)
    {
        sum = 0;
        memset(pos, 0, sizeof(pos));
        memset(cake, 0, sizeof(cake));
        cin >> cake_size;
        cin >> cake_num;
        for (int i = 1; i <= cake_num; i++)
        {
            cin >> edge;
            cake[edge]++;
            sum += edge*edge;
        }
        if (sum != cake_size*cake_size)
        {
            cout << "HUTUTU!" << endl;
            continue;
        }
        if (DFS(0))
            cout << "KHOOOOB!" << endl;
        else cout << "HUTUTU!" << endl;
    }
}

Source: https: //www.cnblogs.com/LHJL8023/p/8018114.html

Guess you like

Origin www.cnblogs.com/sweet-ginger-candy/p/11518192.html