题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143

题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数只使用一次的前提下,分成若干部分,每部分数的长度 >= 3且满足是等差数列。可以的话输出 Yes ,否则 No 。

  比赛的时候过了pretest,那个开心啊~~然后跟 XX 兽讨论了之后,才发现自己理解错了题目= =

  要用到深搜,问组合嘛~~组合就是有可能是(1, 2, 3, 4)、(1, 2, 3)、(2, 3, 4) 与 cnt[1] >= 3 || cnt[1] == 0 { (1, 1, 1), (0)}  ,cnt[2] >= 3 || cnt[2] == 0,cnt[3] >= 3 || cnt[3] == 0, cnt[4] >= 3 || cnt[4] == 0 的组合。

  cnt[i] 表示数字 i 的数量有cnt[i]个。其实总共有16种情况。

  0 0 0 0,  0 0 0 3,  0 0 3 0,  0 0 3 3

  0 3 0 0,  0 3 0 3,  0 3 3 0,  0 3 3 3

  3 0 0 0,  3 0 0 3,  3 0 3 0,  3 0 3 3

  3 3 0 0,  3 3 0 3,  3 3 3 0,  3 3 3 3

  注意:填 3 的那些位置实际上 >= 3 都符合条件的。然后跟(1, 2, 3, 4)、(1, 2, 3)、(2, 3, 4) 组合

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; bool dfs(int a, int b, int c, int d)
{
if ((a >= || !a) && (b >= || !b) && (c >= || !c) && (d >= || !d))// (1,1,1),(2,2,2), (3,3,3), (4,4,4) 的组合
return true;
if (a >= && b >= && c >= && d >= ) // (1, 2, 3, 4)
{
if (dfs(a-, b-, c-, d-))
return true;
}
if (a >= && b >= && c >= ) // (1, 2, 3)
{
if (dfs(a-, b-, c-, d))
return true;
}
if (b >= && c >= && d >= ) // (2, 3, 4)
{
if (dfs(a, b-, c-, d-))
return true;
}
return false;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int T, ta, tb, tc, td;
while (scanf("%d", &T) != EOF)
{
while (T--)
{
scanf("%d%d%d%d", &ta, &tb, &tc, &td);
printf("%s\n", dfs(ta, tb, tc, td) ? "Yes" : "No");
}
return ;
}
}

BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告的更多相关文章

  1. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  2. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

  3. HDU 5143 NPY and arithmetic progression(思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=5143 题意: 给定数字1,2,3,4.的个数每个数字能且仅能使用一次,组成多个或一个等差数列(长度大于等于3), ...

  4. BestCoder20 1002.lines (hdu 5124) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...

  5. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  6. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  7. BestCoder15 1002.Instruction(hdu 5083) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...

  8. BestCoder12 1002.Help him(hdu 5059) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...

  9. BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ...

随机推荐

  1. mysql 调用外部程序

    一.下载 lib_mysqludf_sys: 下载地址:https://github.com/mysqludf/repositories 二.配置与使用: 1.解压之后,已经有了我们需要的 lib_m ...

  2. ngCordova插件安装使用

    为什么ngCordova ngCordova是在Cordova Api基础上封装的一系列开源的AngularJs服务和扩展,让开发者可以方便的在HybridApp开发中调用设备能力,即可以在Angul ...

  3. 【Solr】 solr对拼音搜索和拼音首字母搜索的支持

    问:对于拼音和拼音首字母的支持,当你在搜商品的时候,如果想输入拼音和拼音首字母就给出商品的信息,怎么办呢? 实现方式有2种,但是他们其实是对应的.  用lucene实现 1.建索引, 多建一个索引字段 ...

  4. 终端下使用cocopods

    http://blog.csdn.net/showhilllee/article/details/38398119

  5. block 块函数

    定义模块函数: <?php function smarty_block_text($args,$content,$smarty,$a) { $color=$args["color&qu ...

  6. spring框架搭建url

    MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建 http://blog.csdn.net/zhshulin/article/details/30779873 MyEclipse下 ...

  7. mysql explain用法和结果的含义

    重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...

  8. Mongodb——GridFS

    GridFS用于存储和恢复那些超过16M(BSON文件限制)的文件. GridFS将文件分成大块,将每个大块存储为单独的文件.GridFS中限制chunk最大为256k.GridFS使用两个colle ...

  9. JAVA多线程基础知识(一)

    一. 基础知识 要了解多线程首先要知道一些必要的概念,如进程,线程等等.开发多线程的程序有利于充分的利用系统资源(CPU资源),使你的程序执行的更快,响应更及时. 1. 进程,一般是指程序或者任务的执 ...

  10. UIView的layoutSubviews和drawRect

    原文: UIView的layoutSubviews和drawRect UIView的setNeedsDisplay和setNeedsLayout方法.首先两个方法都是异步执行的.setNeedsDis ...