题目链接: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. 前端性能利器——dynatrace ajax edition

    因为最近的工作跟性能分析有关系,所以写个小总结. 顺带推荐两个我常用的小工具: 1.文件对比工具beyond compare,非常好用,对比.修改很简单.当然我只是用的试用版本.google一下官网下 ...

  2. 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

    从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...

  3. git之remote repository create(远程仓库创建)

    参考:Git教程 - 廖雪峰的官方网站 1.在Git bash窗口执行如下指令创建SSH KEY: ssh-keygen -t rsa -C "sunjf@biomarker.com.cn& ...

  4. MyEclipse 2013优化配置【转】

    作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs MyEclipse 2013优化速度方案仍然主要有这么几个方面:去除无需加载的模块.取消冗余的配置.去除不 ...

  5. ASP.NET实现验证码

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  6. sql种类

  7. Entity Framework Code First数据库自动更新2

    以前做项目的时候,没有采用分类库的形式,所以迁移一致非常顺利,没有出现过任何状况. 这次做项目稍微有点大,必须要分类库才方便开发维护. 在解决方案中启用项目EntityFramework迁移时却发生了 ...

  8. 安装和配置VNC服务器的法则

    导读 这是一个关于怎样在你的 CentOS 7 上安装配置VNC服务的教程.当然这个教程也适合 RHEL 7 .在这个教程里,我们将学习什么是 VNC 以及怎样在 CentOS 7 上安装配置VNC ...

  9. Android学习笔记(十)——ListView的使用(上)

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! ListView绝对可以称得上是 Android中最常用的控件之一,ListView允许用户通过手指上下滑动的 ...

  10. Sqli-LABS通关笔录-16

    这个关卡之前我还使用了一下工具跑,发现居然跑不出来.这就尴尬了.行吧手工试试. payload admin") and If(ascii(substr(database(),1,1))=11 ...