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的更多相关文章

  1. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  2. DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas

    题目传送门 /* DFS:按照长度来DFS,最后排序 */ #include <cstdio> #include <algorithm> #include <cstrin ...

  3. 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 ...

  4. 并查集+bfs+暴力滑窗 Codeforces Round #356 (Div. 2) E

    http://codeforces.com/contest/680/problem/E 题目大意:给你一个n*n的图,然后图上的 . (我们下面都叫做‘点’)表示可以走,X表示不能走,你有如下的操作, ...

  5. 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 ...

  6. Codeforces Round #356 (Div. 2)-B

    B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in B ...

  7. Codeforces Round #356 (Div. 2)-A

    A. Bear and Five Cards 题目链接:http://codeforces.com/contest/680/problem/A A little bear Limak plays a ...

  8. DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots

    题目传送门 /* DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 */ #include <cstdio> #include <iostream> ...

  9. Codeforces Round #356 (Div. 2)

    A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. Linux格式化字符串

    > 常用 > 详细 给定的格式FORMAT 控制着输出,解释序列如下: %% 一个文字的 % %a 当前locale 的星期名缩写(例如: 日,代表星期日) %A 当前locale 的星期 ...

  2. CodeForces 696C PLEASE

    快速幂,费马小定理,逆元. 设$dp[n]$表示$n$次操作之后的概率,那么$dp[n] = \frac{{(1 - dp[n - 1])}}{2}$.$1-dp[n - 1]$表示上一次没有在中间的 ...

  3. screen实现关闭ssh之后继续运行代码

    本文基于Ubuntu 14.04 使用SSH连接远程服务器,启动服务,退出SSH后,服务也就终止了,使用Screen可以解决这个问题. 1.安装Screen apt-get install scree ...

  4. Chapter 2 Open Book——24

    Mike kept up a string of complaints on the way to building four. mike去教学楼的路上一直嘀咕抱怨着. Once inside the ...

  5. JS复习:第二十二章

    一.高级函数 1.在任何值上调用Object原声的toString( )方法,都会返回一个[object NativeConstructorName]格式d字符串.每个类在内部都有一个[[Class] ...

  6. JS面向对象基础2

    根据之前看了面向对象相关的视频,按照自己的理解,整理出相关的笔记,以便自己的深入理解. javascript面向对象: 突发奇想,注意:===全等:是指既比较值,也比较类型(题外话,可忽略) 逻辑运算 ...

  7. POJ 2484 A Funny Game(找规律)

    题目链接 #include<iostream> #include<cstdio> using namespace std; int main() { int n; while( ...

  8. TortoiseGit - 处理冲突

    处理冲突 冲突:远程的master已经被其他人更新到 2repo add 12,但是自己当前的工作区在未pull到最新前,增加了1repo add 12的改动. 右击最新的节点,选择Merge to ...

  9. linux 非root用户 ssh 免密码登录

    之所以要把这个记录下来 是因为它的确和root用户不一样root用户 不需要改动什么权限问题  只要生成私钥/公钥对 即可 但是一样的操作在普通用户上就出了问题了 折腾了老半天 ssh-keygen ...

  10. ( ̄y▽ ̄)~ 智能手机II

    ( ̄y▽ ̄)~ 智能手机II TimeLimit: 3000/1000 MS (Java/Others)  MenoryLimit: 32768/32768 K (Java/Others) 64-bi ...