#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int t,s,n,a,sum,row[],cake[];
void init(){memset(row,,sizeof(row)),memset(cake,,sizeof(cake)),sum=;}
int find(){int p;for(int i=,min=;i<=s;i++)if(min>row[i])min=row[i],p=i;return p;}
int count(int p){int cnt=;for(int i=p;i<=s;i++)if(row[i]==row[p])cnt++;else break;return cnt;}
void put(int p,int x){cake[x]--;for(int i=p;i<=p+x-;i++)row[i]+=x;}
void del(int p,int x){cake[x]++;for(int i=p;i<=p+x-;i++)row[i]-=x;}
bool dfs(int dep) {
if(dep==n)return true;int p=find();
for(int x=;x;x--)if(cake[x]&&row[p]+x<=s&&count(p)>=x){put(p,x);if(dfs(dep+))return true;del(p,x);}
return false;
}
int main() {
for (scanf("%d",&t);t--;) {
init(),scanf("%d%d",&s,&n);
for(int i=;i<=n;i++)scanf("%d",&a),cake[a]++,sum+=a*a;
puts((sum==s*s?dfs():)?"KHOOOOB!":"HUTUTU!");
}
return ;
}

C++-POJ1020-Anniversary Cake[搜索][dfs]的更多相关文章

  1. POJ1020 Anniversary Cake

    题目来源:http://poj.org/problem?id=1020 题目大意:有一块边长为s的正方形大蛋糕,有n个客人,每个客人想分一块边长为si的正方形蛋糕.求这块大蛋糕能否恰好满足所有客人的需 ...

  2. POJ 1020 Anniversary Cake(DFS)

    Anniversary Cake Time Limit: 1000MSMemory Limit: 10000KB64bit IO Format: %I64d & %I64u Submit St ...

  3. 【DFS】Anniversary Cake

    [poj1020]Anniversary Cake Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17203   Accep ...

  4. poj 1020 Anniversary Cake(切正方形蛋糕+搜索)

                                                                                                         ...

  5. Anniversary Cake

    Anniversary Cake Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15704   Accepted: 5123 ...

  6. 简单搜索dfs, 简单的修剪搜索

    选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...

  7. 深度优先搜索DFS和广度优先搜索BFS简单解析(新手向)

    深度优先搜索DFS和广度优先搜索BFS简单解析 与树的遍历类似,图的遍历要求从某一点出发,每个点仅被访问一次,这个过程就是图的遍历.图的遍历常用的有深度优先搜索和广度优先搜索,这两者对于有向图和无向图 ...

  8. 利用广度优先搜索(BFS)与深度优先搜索(DFS)实现岛屿个数的问题(java)

    需要说明一点,要成功运行本贴代码,需要重新复制我第一篇随笔<简单的循环队列>代码(版本有更新). 进入今天的主题. 今天这篇文章主要探讨广度优先搜索(BFS)结合队列和深度优先搜索(DFS ...

  9. POJ 2243 简单搜索 (DFS BFS A*)

    题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...

随机推荐

  1. C#设计模式学习笔记:简单工厂模式(工厂方法模式前奏篇)

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7551373.html,记录一下学习过程以备后续查用. 一.引言 简单工厂模式并不属于GoF23里面的设计模式 ...

  2. C#Linq的10个练习

    1.LINQ的两种语法 LINQ查询时有两种语法可供选择:查询表达式(Query Expression)和方法语法(Fluent Syntax). .NET公共语言运行库(CLR)并不具有查询表达式的 ...

  3. VSCode常用插件汇总

    vscode常用插件汇总: 点击插件名字,查看使用文档 vscode-fileheader : 添加注释到文件头,并支持自动更新文件修改时间. EditorConfig for vs code :   ...

  4. JDBC连接数据库的7个步骤

    1.JDBC所需的四个参数username.password.url.driverClass 2.加载JDBC驱动程序 3.创建数据库连接connection对象conn 4.创建preparedSt ...

  5. Connections in Galaxy War ZOJ - 3261 离线操作+逆序并查集 并查集删边

    #include<iostream> #include<cstring> #include<stdio.h> #include<map> #includ ...

  6. ubuntu set up 5 - VIM

    Edit ~/.vimrc source vimrc: :so ~/.vimrc 1. ctrl - left/right 切换tabs https://vim.fandom.com/wiki/Usi ...

  7. ip连接mysql时报不能连接

    问题:springboot项目在用localhost连接mysql时没问题,但当localhost换成ip时出现 该问题:message from server: "Host 'DESKTO ...

  8. k8s service的四种类型

    ClusterIp 默认类型,每个Node分配一个集群内部的Ip,内部可以互相访问,外部无法访问集群内部. NodePort 基于ClusterIp,另外在每个Node上开放一个端口,可以从所有的位置 ...

  9. data_analysis 第一课

    1.anaconda的安装与使用 在官网下载anaconda的客户端,因为python有2和3之分,所以有两个版本可以供选择,由于该课程使用2作为开发工具,选择anaconda2下载安装. 安装好之后 ...

  10. LED Keychain-Ideal For Mass Promotions

    Looking for something memorable to remind people of your business or nonprofit? Consider custom LED ...