[Shaped pressure DP] [DFS] JZOJ 2679 Era

Description

       And counterclockwise around the clock, hideous evil things out in force, I humbly quietly to Vespers at the castle, the ancient wild repression fled signal, and the organ keys proud to say, it is just in vain. My instrument in surround, not age out of my domineering dynasty. You can not predict, because I was the more dangerous, the more brilliant wings; no dot, cross-age spread wings in the air. Relief under the moon, the devil's smile, the wind howling wolf, bat Xiang like the Kuroshio, lonely go with tints dignity. I've jumped from generation to generation, such as animal-like attitude, piano arouse the sleeping blood. Does not need to be worshiped as animal-like sorrow, it exists only for the eternal music, wake up. After last year's highly anticipated "New Era" album, Jay began his world tour "super-era." Someone once said: If you love a person, you must go to a concert of his; 1m from the front of the TV and even live in concert distance of 100m, two feelings are very different.
       G so small as hardcore fans, also plans to take the small Y to see Jay concert. Of course, to the concert circled a space, and then to arrange props. The first leg of the concert, the company temporarily with the local fire department borrowed a n a railing, intends to use the n railed out a rectangle. The trouble is, these railings have long or short, which brought some difficulties to the paddock land. So the company hired you to write a program, calculated using the n railings do more around the area much rectangle.
(Note: You must be exactly enclose a rectangle, i.e. unwanted side length can not appear, and can not cut off the railing, but not necessarily all of the railing to spend)
 

Input

The first line of a positive integer n, the number of railing.
The second row of n positive integer, and li represents the length of each rail.

Output

 Only one row a positive integer representing a given enclosed railing largest rectangle, if not surrounded by a rectangular, the output "No Solution" (without the quotes).
 

Sample Input

4
1 1 1 1

Sample Output

1
 

Data Constraint

 
 

Hint

 For 30% of the data, 1 <= n <= 10. To 100% of the data, 1 <= n <= 16,1 <= li <= 15.

analysis

n the size of the tips we use like pressure

After we set f [i] denotes the i side of all selected, whether or composition to reach half of the total length of the

This is a relatively simple process DP

Then the DFS, recorded two and two and a long and wide, and the state of the selected edge, and finally determines whether to be divided into half

 

#include <iostream>
#include <cstdio>
#include <memory.h>
using namespace std;
int n,mxb,l[16],f[1<<16];
bool b[500];
int cnt,ans;

void Calc(int S,int s) {
    if (s&1) return;
    memset(b,0,sizeof b);b[0]=1;
    for (int i=0;i<n;i++) {
        if (S<(1<<i)) break;
        if (S&(1<<i))
            for (int j=s;j-l[i]+1;j--)
                b[j]|=b[j-l[i]];
    }
    if (b[s>>1]) f[S]=1;
}

void DFS(int dep=0,int sa=0,int sb=0,int a=0,int b=0) {
    if (dep==n) {
        if (f[sa]&&f[sb]) ans=max(ans,a*b>>2);
        return;
    }
    DFS(dep+1,sa,sb,a,b);
    DFS(dep+1,sa|(1<<dep),sb,a+l[dep],b);
    DFS(dep+1,sa,sb|(1<<dep),a,b+l[dep]);
}

int main() {
    scanf("%d",&n);mxb=1<<n;
    for (int i=0;i<n;i++) scanf("%d",&l[i]);
    for (int i=0;i<mxb;i++) {
        cnt=0;
        for (int j=0;j<n;j++) cnt+=l[j]*((i&(1<<j))>0);
        Calc(i,cnt);
    }
    DFS();
    printf((ans?"%d":"No Solution"),ans);
}
View Code

 

Guess you like

Origin www.cnblogs.com/mastervan/p/11145010.html