Codeforces 6D Lizards and Basements 2 dfs+暴力
题目链接:点击打开链接
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 110
#define ll int ll n, a, b;
ll h[N];
vector<int>G,ans;
void dfs(int u, bool hehe){//hehe=true表示u-1没死
if(u==n && hehe==false){
if(G.size()<ans.size())
ans = G;
return ;
}
int siz = 0;
if(hehe) {
while(h[u-1]>0)siz++,h[u-1]-=b, h[u]-=a, h[u+1]-=b, G.push_back(u);
}
if(h[u]>0) {
while(h[u]>0) {
dfs(u+1,true);
h[u-1]-=b;
h[u]-=a;
h[u+1]-=b;
siz++;
G.push_back(u);
}
}
dfs(u+1,false);
h[u]+=a*siz;
h[u+1]+=b*siz;
h[u-1]+=b*siz;
while(siz--)G.erase(G.end()-1);
}
int main(){
ll i, j;
while(~scanf("%d %d %d",&n,&a,&b)){
G.clear(); ans.clear();
for(i=1;i<=n;i++)scanf("%d",&h[i]), h[i]++;
while(h[1]>0){
h[2] -= a;
h[1] -= b;
h[3] -= b;
ans.push_back(2);
}
while(h[n]>0){
h[n-2] -= b;
h[n-1] -= a;
h[n] -= b;
ans.push_back(n-1);
}
G = ans;
for(i=1;i<=100;i++)ans.push_back(i);
dfs(2,false);
printf("%d\n",ans.size());
for(i = 0; i < ans.size(); i++)printf("%d%c",ans[i],i==ans.size()-1?'\n':' ');
}
return 0;
} /**/
Codeforces 6D Lizards and Basements 2 dfs+暴力的更多相关文章
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dfs
D. Lizards and Basements 2 题目连接: http://codeforces.com/contest/6/problem/D Description This is simpl ...
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dp
题目链接: http://codeforces.com/problemset/problem/6/D D. Lizards and Basements 2 time limit per test2 s ...
- codeforces 6D
D. Lizards and Basements 2 time limit per test 2 seconds memory limit per test 64 megabytes input st ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- hdu 5612 Baby Ming and Matrix games(dfs暴力)
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...
- hdu 1010 Tempter of the Bone(dfs暴力)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- NOIP 2002提高组 选数 dfs/暴力
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...
随机推荐
- 实用的表格内省略号和换行(兼容IE6)
让连续的英文数字字符换行显示 word-break: break-all; 让单行文字超出的时候使用点点点表示 white-space: nowrap; overflow: hidden; text- ...
- MongoDB学习笔记(六)--复制集+sharding分片 && 总结
复制集+sharding分片 背景 主机 IP 服务及端口 Server A ...
- 网络结构设计——负载均衡之LVS学习笔记(三)
LVS按个人理解的说就是将一台Linux服务器当作路由器等功能的技术.LVS---Linux虚拟服务器. LVS实现了三种IP负载均衡技术VS/NAT.VS/TUN.VS/DR. 今天简单分享一下我在 ...
- CentOs中mysql服务器重置root密码方法
1. 停止mysql: service mysqld stop 2. 编辑/etc/my.cnf,在[mysqld]这行后面加上skip-grant-tables ,并保存 3. 启动mysql: s ...
- Linux命令行和Shell高效率使用方法
Ctrl+R快速搜索history Ctrl+P显示上一条命令 快速执行一条history命令:!!/!-number ======================================== ...
- MFC画图总结-DIB图形绘制
參考文档: http://blog.csdn.net/hnust_xiehonghao/article/details/37652927 http://blog.sina.com.cn/s/blog_ ...
- Linux操作系统安装与VMTools的安装
Linux操作系统安装:虚拟机+RedHat 1.安装虚拟机VMware_WorkstationV7.1.3 2.安装RedHat 自动安装(会自动安装VMTools): 打开虚拟机-->新建虚 ...
- eclipse使用egit插件
本来想用myeclipse,奈何试过网上所列的常用方法,都无法成功安装egit插件.只得转到eclipse.话说eclipse不仅是免费的,启动也较myeclipse更为迅速,安装插件也非常顺利.使用 ...
- Vue 生命周期LIFECYCLE是8个吗?
vue生命周期钩子个数是:11个. export const LIFECYCLE_HOOKS = [ 'beforeCreate', 'created', 'beforeMount', 'mounte ...
- MariaDB卸载
二进制安装方式的MariaDB卸载 关闭mysql服务 service mysql stop 或 /etc/init.d/mysql stop 或 mysqladmin shutdown -uroot ...