题目链接: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. CF467D Fedor and Essay 建图DFS

      Codeforces Round #267 (Div. 2) CF#267D D - Fedor and Essay D. Fedor and Essay time limit per test ...

  2. Linux内核循环链表经典分析和移植

    为什么说这个链表做的经典呢,哥哥我从Linux内核里边儿扣出来的,要么怎么说内核不是一般人能写的,这代码太TM优美了! 这里有一篇参考文章:http://isis.poly.edu/kulesh/st ...

  3. Java实验2-数据库编程

    目标:掌握Java数据库编程 内容: 学生选课系统包括如下数据库表 学生表:Student(Sno,Sname,Ssex,Sage,Sdept) 课程表:Course(Cno,Cname,Ccredi ...

  4. [译]Mongoose指南 - Model

    编译你的第一个model var xxSchema = new Schema({name: 'string', size: 'string'}); var Tank = mongoose.model( ...

  5. getField方法

    getField方法是ThinkPHP中用来获取字段值的方法,区别于select和find方法,通常仅用于获取个别字段的值.但是事实上并没有那么简单,该方法的用法总结如下: 获取某个字段值这个是get ...

  6. 分享一个c#t的网页抓取类

    using System; using System.Collections.Generic; using System.Web; using System.Text; using System.Ne ...

  7. UNIX Time 时间戳 与 北京时间 相互转换

    typedef struct t_xtime { int year; int month; int day; int hour; int minute; int second; } _xtime ; ...

  8. 安装JBPM6运行环境(JBPM6学习之二)

    安装Eclipse插件成功后,需要配置JBPM6的运行环境: 1. 第一步先将下载的jbpm6目录中的“jbpm-6.0.1.Final-bin.zip”找到,并解压缩到D盘根目录备用. 2. 第二步 ...

  9. Unity3D性能优化--- 收集整理的一堆

    http://www.cnblogs.com/willbin/p/3389837.html 官方优化文档--优化图像性能http://docs.unity3d.com/Documentation/Ma ...

  10. objc/runtime

    "T@\"MyInnerObject\",&,N,V_myInnerObject" MyInnerObject "Td,N,V_cgfloat ...