zoukankan      html  css  js  c++  java
  • hdu1518 bjfuoj1042 zoj1909 poj2362 经典的搜索加剪枝

    bjfuoj的测试数据最水,用很简单的方法一下就过了,又调了好长时间,才过掉其它OJ上的这道题目~

    /*
    * hdu1518/win.cpp
    * Created on: 2011-11-8
    * Author : ben
    */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const int MAXN = 25;
    int lens[MAXN];
    bool visited[MAXN];
    int N, ave, cur_tol_len, totallen;

    inline bool cmp(const int &a, const int &b) {
    return a > b;
    }

    bool myfind(int step, int num) {
    if (num > 3) {
    return true;
    }
    if (step >= N) {
    return false;
    }
    if (!visited[step] && (lens[step] + cur_tol_len) <= ave * num) {
    visited[step] = true;
    cur_tol_len += lens[step];
    if(cur_tol_len == ave * num) {
    if(myfind(0, num + 1)) {
    return true;
    }
    }else if (myfind(step + 1, num)) {
    return true;
    }
    visited[step] = false;
    cur_tol_len -= lens[step];
    }
    return myfind(step + 1, num);
    }

    bool judge() {
    if (N < 4 || totallen % 4 != 0) {
    return false;
    }
    ave = totallen / 4;
    for (int i = 0; i < N; i++) {
    if (lens[i] > ave) {
    return false;
    }
    }
    sort(lens, lens + N, cmp);
    memset(visited, false, sizeof(visited));
    cur_tol_len = 0;
    return myfind(0, 1);
    }

    int main() {
    #ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    #endif
    int T;
    scanf("%d", &T);
    while (T--) {
    scanf("%d", &N);
    totallen = 0;
    for (int i = 0; i < N; i++) {
    scanf("%d", &lens[i]);
    totallen += lens[i];
    }
    if (judge()) {
    puts("yes");
    } else {
    puts("no");
    }
    }
    return 0;
    }



  • 相关阅读:
    团队冲刺1 5.2
    梦断代码03
    梦断代码02
    梦断代码01
    软工超越日报-paddle目标检测 数据集标注(1) 5/23
    软工超越日报-paddle目标检测 数据清洗(3) 5/22
    软工超越日报-paddle目标检测 数据清洗(2) 5/21
    软工超越日报-paddle目标检测 数据清洗(1) 5/20
    软工超越日报-paddleYOLO预测——数据集图片爬取 5/19
    软工超越日报-团队绩效评分 5/18
  • 原文地址:https://www.cnblogs.com/moonbay/p/2241638.html
Copyright © 2011-2022 走看看