zoukankan      html  css  js  c++  java
  • hdu 1518

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;

    struct node{
    int length;
    }Len[21];
    bool vis[21];
    int n,len;

    bool cmp(node a,node b){
    return a.length>b.length;
    }

    bool Dfs(int l,int cout,int pas){

    if(cout==4)
    return true;
    for(int i=pas;i<n;i++){
    if(vis[i]==true)
    continue;
    if(len==l+Len[i].length){
    vis[i]=true;
    if(Dfs(0,cout+1,0))
    return true;
    vis[i]=false;
    }
    else if(len>(l+Len[i].length)){
    vis[i]=true;
    l+=Len[i].length;
    if(Dfs(l,cout,i+1))
    return true;
    l-=Len[i].length;
    vis[i]=false;
    }
    }
    return false;
    }

    int main(){

    int t;
    cin>>t;
    while(t--){
    cin>>n;
    len=0;
    for(int i=0;i<n;i++){
    cin>>Len[i].length;
    len+=Len[i].length;
    vis[i]=false;
    }
    if(len%4){
    cout<<"no"<<endl;
    continue;
    }
    len/=4;
    sort(Len,Len+n,cmp);
    if(len<Len[0].length){
    cout<<"no"<<endl;
    continue;
    }
    if(Dfs(0,0,0))
    cout<<"yes"<<endl;
    else
    cout<<"no"<<endl;
    }
    return 0;
    }

  • 相关阅读:
    day23
    day22
    day21
    day20
    day19
    day18
    day17
    day16
    day15
    PowerDesigner中NAME和COMMENT的互相转换,需要执行语句
  • 原文地址:https://www.cnblogs.com/huaixiaohai2015/p/5181544.html
Copyright © 2011-2022 走看看