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 ...
随机推荐
- cocos2d-lua ARPG手机游戏《烈焰遮天》(客户端+服务端+数据库)发布说明
服务器发布流程及其规范1,环境准备 a, mvn命令行:从\\10.21.210.161\share\tools\apache-maven-3.1.1-bin.tar.gz取出安装包, ...
- BOS物流管理系统-第一天
BOS物流管理系统-第一天-系统分析.环境搭建.前端框架 BoBo老师 整体项目内容目标: 对项目概述的一些理解 亮点技术的学习 注意学习方式:优先完成当天代码. 其他内容. 最终: 学到新的技术,会 ...
- 手机浏览器无法获取COOKIE的原因
手机浏览器上无法使用cookie,肯能是 1. 浏览器禁用 COOKIE ,这个简单开启即可. 2. 可能是手机所在时区有问题,将COOKIE有效期设置更长时间测试下,在更改时区
- ManyToMany OrderBy
有A.B表和A_B中间表,A_B中间表只有A.B表的id,想让A中的bs以date列排序: @Entity @Table(name="A") public class A impl ...
- javascript基础(二)类型转换
原文http://pij.robinqu.me/ 类型转换 当期望使用一个布尔值的时候,可以提供任意类型值,JavaScript将根据需要自行转换类型.类型转换可以分为隐式转换和显式转换. 显式转换 ...
- [POJ] String Matching
String Matching Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4074 Accepted: 2077 D ...
- VS中调试时监控线程的最后错误代码
进行调试的时候,监控线程的最后错误代码是非常有用的. 在 Microsoft Visual studio 中,Microsoft 的调试程序支持一个非常有用的特性,即可以配置 Watch 窗口,以便始 ...
- python学习入门第一天总结
虽然之前自己也看过许多关于python的视频,但一直没有动力与勇气,所以未能坚持且也没有学得这么深刻,这次希望通过python自动化培训,能够彻底改变自己,通过第一天的python学习,自己学到了许多 ...
- 感知哈希算法 python 3.4
#!/usr/bin/python # -*- coding: UTF-8 -*- #Less than 10 add to list and sort import glob import os i ...
- python--zeros函数和ones函数
使用numpy.zeros,numpy.ones,numpy.eye等方法可以构造特定的矩阵 例如: 代码如下: >>>from numpy import * >>> ...