Content

圣诞老人有 \(n\) 颗糖果,他想把这些糖果分发给一些小孩子,并想要每个孩子都能得到不同的糖果数目。求能得到糖果的孩子的最大数目,以及他们各自得到的糖果数。

数据范围:\(1\leqslant n\leqslant 1000\)。

Solution

我们可以往下枚举每个小孩的糖果数目,然后不断地深入搜索,然后得到的第一个合法的方案就是我们想要的得到糖果的孩子的最大数目,直接输出方案即可。

Code

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std; int n, vis[1007]; void dfs(int x) {
if(!x) {
int ans = 0;
for(int i = 1; i <= n; ++i) ans += vis[i];
printf("%d\n", ans);
for(int i = 1; i <= n; ++i)
if(vis[i]) printf("%d ", i);
exit(0);
}
for(int i = 1; i <= x; ++i) {
if(!vis[i]) {
vis[i] = 1;
dfs(x - i);
vis[i] = 0;
}
}
} int main() {
scanf("%d", &n);
dfs(n);
}

CF753A Santa Claus and Candies 题解的更多相关文章

  1. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...

  2. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  3. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Codeforces Round #389 Div.2 E. Santa Claus and Tangerines

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Codeforces Round #389 Div.2 C. Santa Claus and Robot

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. Codeforces Round #389 Div.2 A. Santa Claus and a Place in a Class

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. [bzoj5295]染色

    将这张图化简,不断删掉度为1的点(类似于拓扑排序),构成了一张由环组成的图考虑一个连通块中,设点数为n,边数为m(已经删掉了度为1的点),那么一共只有三种情况:1.一个环($n=m$),一定为YES2 ...

  2. lilypond进阶——用scheme修改乐谱细节

    lilypond对乐谱内容的修改非常自由,用户可以自由根据需要做调整 调整一般都是用\override的命令,但是会比较冗长,码代码的时候比较麻烦 重新设置一个函数来概括命令,调用的时候使用的代码更短 ...

  3. 微服务改造之Openfeign的强化插件

    在接触 Spring Cloud 这套框架之前,笔者使用的一直是Dubbo.在转型到Spring Cloud 后,发现了一个很郁闷的问题.Spring Cloud 中的 Openfeign,相比于 D ...

  4. 链式调用Builder

    使用Lombok实现链式调用 1.静态调用 User对象: 对象中必须有一个值不为空staticname作为指定的参数并调用对象 @Accessors(chain = true) @Getter @S ...

  5. MySQL的B+树索引和hash索引的区别

    简述一下索引: 索引是数据库表中一列或多列的值进行排序的一种数据结构:索引分为聚集索引和非聚集索引,聚集索引查询类似书的目录,快速定位查找的数据,非聚集索引查询一般需要再次回表查询一次,如果不使用索引 ...

  6. SpringBoot引入第三方jar的Bean的三种方式

    在SpringBoot的大环境下,基本上很少使用之前的xml配置Bean,主要是因为这种方式不好维护而且也不够方便. 因此本篇博文也不再介绍Spring中通过xml来声明bean的使用方式. 一.注解 ...

  7. P4569 [BJWC2011]禁忌

    题目传送门. 题意简述:给出大小为 \(n\) 的字典 \(s\).设函数 \(g(t)\) 表示 \(t\) 最多能被分割成的单词个数.等概率随机生成长度为 \(len\) 的字符串 \(T\),求 ...

  8. 【R】行或列数目不同的两个数据框如何用rbind/cbind合并?

    目录 前言 方法一:dplyr的bind_rows 方法二:plyr的rbind.fill 前言 通常我们用rbind和cbind合并相同行列的数据框.当两个数据框具有不同行列数目时,直接用会报错. ...

  9. arm三大编译器的不同选择编译

    ARM 系列目前支持三大主流的工具链,即ARM RealView (armcc), IAR EWARM (iccarm), and GNU Compiler Collection (gcc).     ...

  10. 以DevExpress开发的WinFrom程序的多语言功能的实现

    以DevExpress开发的WinFrom程序的多语言功能的实现 写在前面: 多语言切换功能在Winform程序中是经常遇到的需求,尤其是需要给国外客户使用的情况下,多语言功能是必不可少的.前一段时间 ...