CF753A Santa Claus and Candies 题解
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 题解的更多相关文章
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- SpringCloud升级之路2020.0.x版-41. SpringCloudGateway 基本流程讲解(3)
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 我们继续分析上一节提到的 WebHandler.加入 Spring Cloud Sleut ...
- 架构师必备:巧用Canal实现异步、解耦的架构
本文介绍如何应用Canal实现异步.解耦的架构,后续有空再写文章分析Canal原理和源代码. Canal简介 Canal是用来获取数据库变更的中间件. 伪装自己为MySQL从库,拉取主库binlog并 ...
- .net core 3.1 WebAPi 使用 AutoMapper 9.0、10.0
AutoMapper 可以很方便完成数据对象之间的转换. Dto -> Entity Entity -> ViewModel Step 1:通过 NuGet 安装 AutoMapper 的 ...
- 洛谷 P6499 - [COCI2016-2017#2] Burza(状压 dp)
题面传送门 一道挺有意思的思维题(?) 首先我们假设根节点深度为 \(0\),那么 Daniel 的目标显然就是堵住一些节点使得 Stjepan 不能移动到深度为 \(k\) 的节点,Stjepan ...
- cookie的生命周期、访问限制、作用域、prefixes
cookie的生命周期 cookie的生命周期可以通过两种方式定义: 会话期cookie是最简单的cookie:浏览器关闭后会被自动删除.会话期cookie不需要指定过期时间(Expires)或者有效 ...
- Neville 插值方法
简介 wikipedia: Neville's method 在数学上,Neville 算法是一种计算插值多项式方法,由数学家Eric Harold Neville提出.由给定的n+1个节点,存在一个 ...
- [linux] 大批量删除任务
一不小心投了巨多任务,或者投递的资源不合理时,想批量杀掉这些任务. kill的方法就不说了,我这里用qdel的方法. 用了这么一条命令: qstat |sed '1,2d' |awk -F' ' '{ ...
- R语言与医学统计图形-【26】ggplot2主题函数
ggplot2绘图系统--主题函数 1. theme函数 theme_*系列函数提供了9种不同的风格. theme_grey/gray/bw/linedraw/light/minimal/classi ...
- android studio Please configure Android SDK / please select Android SDK
有可能是sdk文件损坏造成的. file->settings->appearance&behavior->system settings->android sdk-&g ...
- flink---实时项目----day03---1.练习讲解(全局参数,数据以parquet格式写入hdfs中) 2 异步查询 3 BroadcastState
1 练习讲解(此处自己没跑通,以后debug) 题目见flink---实时项目---day02 kafka中的数据,见day02的文档 GeoUtils package cn._51doit.flin ...