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 ...
随机推荐
- linux下安装php的mcrypt拓展
安装步骤: 1,#wget http://museum.php.net/php5/php-5.3.3.tar.gz 2,解压:#tar -zxvf php-5.3.3.tar.gz 3,#cd ...
- C#指定某用户对某文夹件的访问权限
using System.Security.AccessControl; //设置myFloder文件夹的iis访问权限 string userAccount = @&q ...
- java 读取excel文件(只读取xls文件)
package com.sun.test; import java.io.BufferedInputStream;import java.io.File;import java.io.FileInpu ...
- PBO
#include <GL/glew.h> #include <GL/freeglut.h> #include <iostream> GLuint pboID[]; ...
- JSP的改动需要重启应用服务器才能生效?
PLM的版本由2013版升级到2016版,部署到应用服务器tomEE的war包也更新了,今天在Linux服务器上hot fix一个JSP页面的时候发现改动没有生效,要重启tomEE才生效,纳闷了一下才 ...
- Xshell连接服务器密钥改成密码登录
密钥登陆 直接点本地shell打开之后直接ssh ip连接 需要centos用户登录,选择机器密钥. 登录后 sudo su - root 修改root密码 passwd root 修改文件 vi / ...
- UNIX基础--控制台和终端
虚拟控制台和终端 Virtual Consoles and Terminals: FreeBSD 虚拟控制台的默认配置为8个,但并不是硬性设置, 您可以很容易设置虚拟控制台的个数增多或减少. 虚拟控制 ...
- 获取用户IP地址
// <summary> /// 取得客户端真实IP.如果有代理则取第一个非内网地址 /// by flower.b /// </summary> public static ...
- CURL访问url显示响应时间
curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} http://www.baidu.com 时间指 ...
- webupload-upload执行上传时,进入的路径与linux服务器上的不一致
将if判断处改为garage即可. 原因是因为if处判断处理没有执行,因为要需要把从garage开始的到后面的字符串都去掉才行 不然:local=http://www.xxx.com/garage s ...