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 ...
随机推荐
- Android 关于 OnScrollListener 事件顺序次数的简要分析
在 Android 的 OnScrollListener 整个事件我主要分析下他的执行顺序: 实现滚动事件的监听接口 new AbsListView.OnScrollListener(){ @Over ...
- POJ 2656 Unhappy Jinjin
#include <stdio.h> int main() { ) { int i, n; ; scanf("%d", &n); ) break; ; i &l ...
- 1、SpringMVC+MyBaits实现查询所有
1.创建如下所示项目 2.在src下的com.entity包下创建 Emp.java package com.entity; /** * * @author Holly老师 * */ public c ...
- JVM基础01-内存分配
一.什么是JVM Java作为主流编程语言: 它摆脱了硬件的束缚,一处编写,处处运行: 它提供了一种相对安全的内存管理和访问机制,避免了大部分的内存泄露和指针越界问题: 它实现了热点代码的检测和运行时 ...
- MTK平台Android项目APK预置方案
项目开发中,通常需要向系统中预置一些APK,这里简单介绍一下MTK平台预置APK的方法. 需要预置的apk可以放置在目录:vendor/mediate/${Project}/artifacts/out ...
- 关于erlang的binary
引自:http://cryolite.iteye.com/blog/1547252 1. binary数据是可以在不同进程间共享的 当然这些进程都在同一Erlang节点上. 这与普通term不同,后者 ...
- Ajax.BeginForm 异步上传附件 替代方案
一:问题描述 含有文件信息表单内容,想通过异步上传到服务器,但是使用Ajax.BeginForm上传时,后台无法获取文件信息 二:解决方案 通过 $.ajaxFileUpload 可以实现文件及 ...
- 基于Flash与window平台本地程序通信实现媒体流发布
0 Web场景下的媒体流发布可以采用Flash原生API实现,但是Flash H264视频压缩参数不可控.音频无法AAC编码,所以一般采用浏览器插件方式,但是浏览器插件有版本兼容问题.不稳定,所以可以 ...
- ELK 基本搭建
ELK是一套日志分析系统: 开发人员不能登录线上服务器查看详细日志各个系统都有日志,日志数据分散难以查找日志数据量大,查询速度慢,或者数据不够实时一个调用会设计多个系统,难以在这些系统的日志中快速定位 ...
- 将数据动态加载到Echarts饼图中
需求描述 Echarts中的官方示例是将数据的设定写好在页面的配置项中的,但在实际的开发展示中,我们需要按照需求通过调用后台的接口获取数据,再将数据加载到特定的Echarts饼图中. 实现效果 实现步 ...