dfs Codeforces Round #356 (Div. 2) D
http://codeforces.com/contest/680/problem/D
题目大意:给你一个大小为X的空间(X<=m),在该空间内,我们要尽量的放一个体积为a*a*a的立方体,且每次放入的立方体的体积要尽可能大,问最多能放几块?
感觉自己还是太菜了。。。这种题目都做不来TAT
思路:因为每次都要放入,我们找一下情况以后可以发现,假设当前的体积为x,如果要让cnt个数最多,要么就是要减去x-a*a*a,要么就是让x直接等于a*a*a-1,因此我们很容易就可以得到这是一个dfs的条件,然后我们只要利用dfs就好了
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ;
LL m, cnt;
LL dp[maxn];
map<LL, pair<LL, LL> > mp;///val, cnt and val pair<LL, LL> dfs(LL m){
if (m == ) return mk(, );
if (mp.count(m)) return mp[m];
pair<LL, LL> &tmp1 = mp[m];
int pos = lower_bound(dp + , dp + + cnt, m) - dp;
if (dp[pos] != m) pos--;
tmp1 = dfs(m - dp[pos]);
tmp1.fi += , tmp1.se += dp[pos]; pair<LL, LL> tmp2 = dfs(dp[pos] - );
return tmp1 = max(tmp1, tmp2);
} int main(){
scanf("%lld", &m);
for (LL i = ; 1LL*i*i*i <= m; i++) dp[i] = 1LL * i * i * i, cnt = i;
cnt++;
dp[cnt] = 1LL * cnt * cnt * cnt;
pair<LL, LL> res = dfs(m);
printf("%lld %lld\n", res.fi, res.se);
return ;
}
dfs Codeforces Round #356 (Div. 2) D的更多相关文章
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
题目传送门 /* DFS:按照长度来DFS,最后排序 */ #include <cstdio> #include <algorithm> #include <cstrin ...
- Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs
D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak i ...
- 并查集+bfs+暴力滑窗 Codeforces Round #356 (Div. 2) E
http://codeforces.com/contest/680/problem/E 题目大意:给你一个n*n的图,然后图上的 . (我们下面都叫做‘点’)表示可以走,X表示不能走,你有如下的操作, ...
- Codeforces Round #356 (Div. 2) E. Bear and Square Grid 滑块
E. Bear and Square Grid 题目连接: http://www.codeforces.com/contest/680/problem/E Description You have a ...
- Codeforces Round #356 (Div. 2)-B
B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in B ...
- Codeforces Round #356 (Div. 2)-A
A. Bear and Five Cards 题目链接:http://codeforces.com/contest/680/problem/A A little bear Limak plays a ...
- DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots
题目传送门 /* DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 */ #include <cstdio> #include <iostream> ...
- Codeforces Round #356 (Div. 2)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- pthon之异常、文件练习题
1.在当前目录下查找文件夹“电摄班”,如果不存在则创建2.在电摄班下创建boys.girls.两个txt文件3.将字典中属于电摄班的同学按男女区分,分别放到boys.girls文件中,每个名字在文件中 ...
- TortoiseGit HTTPS方式保存密码最简单的方法
在TortoiseGit的设置 -> git 中选择 编辑本地 .git/config 在最后增加下面内容: [credential] helper = store
- javaWEB总结(8):自定义GenericServlet
前言: 项目的实际应用中,我们往往为了方便去继承GenericServlet类,而不是去实现Servlet接口,是什么原因呢?下面进行简单的实践操作. 一. 准备工作 1.首先看GenericServ ...
- 第六十一节,html超链接和路径
html超链接和路径 学习要点: 1.超链接的属性 2.相对与绝对路径 3.锚点设置 本章主要探讨HTML5中文本元素 ...
- 2016 JetBrains 开发者日遇见开发神器的创造者
JetBrains团队首次落地中国北京!2016 JetBrains开发者日将于2016年11月26日星期六10:00-16:30在中国北京举办! 这一次,我们将与社区演讲者一起谈论现代软件开发语言. ...
- javascript动画:velocity.js学习
第二章:基础知识 一.velocity和jQuery: Velocity函数是独立于jQuery的,但两者可以结合使用.通常这么做的好处是可以利用jQuery的链式操作:当你先用jQuery选择了一个 ...
- 关于图计算和graphx的一些思考[转]
原文链接:http://www.tuicool.com/articles/3MjURj “全世界的网络连接起来,英特纳雄耐尔就一定要实现.”受益于这个时代,互联网从小众的角落走到了历史的中心舞台.如果 ...
- GlusterFS无法启动原因及处理方案
启动结果: Redirecting to /bin/systemctl status glusterd.serviceglusterd.service - GlusterFS, a clustere ...
- WEB前端组件思想【分页】
DEMO1: 很早就想写一些功能性的组件,无奈技术有限一点一点的边工作,边学. 近日工作中用到分页功能,当然由于加快业务进度,第一选择肯定是选择插件,但是实用性来说,还是有那么一点不适合.毕竟插件是通 ...
- POJ 2039 To and Fro
To and Fro Description Mo and Larry have devised a way of encrypting messages. They first decide sec ...