题目链接:点击打开链接

#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+暴力的更多相关文章

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

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

  3. codeforces 6D

    D. Lizards and Basements 2 time limit per test 2 seconds memory limit per test 64 megabytes input st ...

  4. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  5. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

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

  7. hdu 1010 Tempter of the Bone(dfs暴力)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  8. NOIP 2002提高组 选数 dfs/暴力

    1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...

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

随机推荐

  1. retrofit okhttp RxJava bk Gson Lambda 综合示例【配置】

    项目地址:https://github.com/baiqiantao/retrofit2_okhttp3_RxJava_butterknife.git <uses-permission andr ...

  2. 你可能不知道的5 个强大的HTML5 API 函数

    HTML5提供了一些非常强大的JavaScript和HTML API,来帮助开发者构建精彩的桌面和移动应用程序.本文将介绍5个新型的API,希望对你的开发工作有所帮助. 1.  全屏API(Fulls ...

  3. 解析XML并将信息封装到对象中

    [person.xml]要解析的内容 <?xml version="1.0" encoding="UTF-8"?> <students> ...

  4. Android -- 程序启动画面 Splash

    很多应用都会有一个启动界面.欢迎画面慢慢隐现,然后慢慢消隐. 我的方式是使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一 ...

  5. Passing address of non-local object to __autoreleasing parameter for write-back

    在希望通过函数的參数返回Objective-C对象的时候.遇到了这个问题 错误代码例如以下: - (void)methodA:(NSString **)string<span style=&qu ...

  6. Discuz常见大问题-如何允许用户插入视频-如何自己在页面中插入视频

    从视频的下面分享中获取html代码 然后粘贴到你创建页面的指定位置(注意从优酷复制的视频宽度和高度可能比较小,你可以自己调整,或者占据100%) 最终的实现效果

  7. touch 命令(转)

    原文:http://www.cnblogs.com/peida/archive/2012/10/30/2745714.html linux的touch命令不常用,一般在使用make的时候可能会用到,用 ...

  8. _PyUnicodeUCS4_AsDefaultEncodedString

    "_PyUnicodeUCS4_AsDefaultEncodedString"的出现一般源于你在两个地方分别装了python,两个分别用UCS2和UCS4编码进行的build. 解 ...

  9. table布局 防止table变形 td固定宽度

    防止table变形 td固定宽度 具体设置如下代码: <!doctype html> <html lang="en"> <head> <m ...

  10. Android Bitmap与String互转(转)

    /** * 图片转成string * * @param bitmap * @return */ public static String convertIconToString(Bitmap bitm ...