转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Xenia and Weights

Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes on the left scalepan, the fourth one goes on the right scalepan and so on. Xenia wants to put the total of m weights on the scalepans.

Simply putting weights on the scales is not interesting, so Xenia has set some rules. First, she does not put on the scales two consecutive weights of the same weight. That is, the weight that goes i-th should be different from the (i + 1)-th weight for any i (1 ≤ i < m). Second, every time Xenia puts a weight on some scalepan, she wants this scalepan to outweigh the other one. That is, the sum of the weights on the corresponding scalepan must be strictly greater than the sum on the other pan.

You are given all types of weights available for Xenia. You can assume that the girl has an infinite number of weights of each specified type. Your task is to help Xenia lay m weights on ​​the scales or to say that it can't be done.

Input

The first line contains a string consisting of exactly ten zeroes and ones: the i-th (i ≥ 1) character in the line equals "1" if Xenia has i kilo weights, otherwise the character equals "0". The second line contains integer m (1 ≤ m ≤ 1000).

Output

In the first line print "YES", if there is a way to put m weights on the scales by all rules. Otherwise, print in the first line "NO". If you can putm weights on the scales, then print in the next line m integers — the weights' weights in the order you put them on the scales.

If there are multiple solutions, you can print any of them.

Sample test(s)
input
0000000101
3
output
YES
8 10 8
input
1000000000
2
output
NO

div2的C题,果断选择暴搜,搜到不符合的就往回跳,搜到正解就结束。。。

dp的话用dp[i][j][k]表示取到第i个的时候前一个重的一头比轻的重j且取的为k是否满足

 //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
string str;
int a[];
int b[];
bool flag=;
int n;
int tot;
int dfs(int d,int lx,int rx){
if(d==n){
flag=;
return ;
}
int x;
x=upper_bound(a,a+tot,lx-rx)-a;
for(int i=x;i<tot;i++){
if(a[i]==b[d-])continue;
b[d]=a[i];
if(dfs(d+,rx+a[i],lx)){
return ;
}
}
return ;
} int main()
{
ios::sync_with_stdio(false);
cin>>str;
cin>>n;
tot=;
fill(a,a+,INF);
for(int i=;i<str.length();i++)
if(str[i]=='')a[tot++]=i+;
ll lx=,rx=;
int ans=;
int last=;
int i;
int x=;
for(int i=;i<tot;i++){
b[]=a[i];
if(dfs(,a[i],))break;
}
if(flag){
cout<<"YES"<<endl;
for(int i=;i<n;i++){
if(i)cout<<" ";
cout<<b[i];
}
cout<<endl;
}
else cout<<"NO"<<endl; return ;
}

代码君

codeforces 339C Xenia and Weights(dp或暴搜)的更多相关文章

  1. CodeForces 339C Xenia and Weights(暴力求解DFS)

    题意:给定 1-10的某几种砝码,给定的每种有无穷多个,然后放 m 个在天平上,要满足,相邻的两次放的砝码不能是同一种,然后是在天平两端轮流放,并且放在哪一个托盘上,那么天平必须是往哪边偏. 析:这个 ...

  2. codeforces 339C Xenia and Bit Operations(线段树水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginn ...

  3. codevs 1085 数字游戏 dp或者暴搜

    1085 数字游戏 2003年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单 ...

  4. [codeforces 339]C. Xenia and Weights

    [codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...

  5. Codeforces 1519F - Chests and Keys(暴搜+以网络流为状态的 dp)

    Codeforces 题目传送门 & 洛谷题目传送门 难度终于出来了--又独立切掉一道 *3200,凯信(所以我已经独立切掉三道 *3200 了?) 首先考虑我们已经知道了每个宝箱上有哪些锁, ...

  6. Xenia and Weights(深度优先搜索)

    Xenia and Weights time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. suoi62 网友跳 (暴搜+dp)

    传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...

  8. 子矩阵(暴搜(全排列)+DP)

    子矩阵(暴搜(全排列)+DP) 一.题目 子矩阵 时间限制: 1 Sec  内存限制: 128 MB 提交: 1  解决: 1 [提交][状态][讨论版] 题目描述 给出如下定义: 1. 子矩阵:从一 ...

  9. CodeForces - 357D - Xenia and Hamming

    先上题目: D. Xenia and Hamming time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. C/C++中的空类及抽象类大小

    代码: #include <iostream> using namespace std; struct A{ }; struct B{ int i; }; class C:B{ ; }; ...

  2. 在shell中运行以不同方式运行脚本

    在shell当中,可以有3中方式运行脚本: 1 . ./script_name 或者source ./script_name 2 直接./script_name 3 ./script_name &am ...

  3. Java学习笔记——可视化Swing中JTable控件绑定SQL数据源的两种方法

    在 MyEclipse 的可视化 Swing 中,有 JTable 控件. JTable 用来显示和编辑常规二维单元表. 那么,如何将 数据库SQL中的数据绑定至JTable中呢? 在这里,提供两种方 ...

  4. Android 多渠道打包,上百渠道,秒打签名

    具体工具参见:https://github.com/hpu-spring87/MultiSignTools

  5. shell中的for、while、until

    for var in list do commands done 在每个迭代中,变量var会包含列表中的当前值,第一个迭代会使用列表中的第一个值,第二个迭代使用第二个值. 在do和done中,$var ...

  6. 动态修改ActionBar Menu的显示

    应用场景: 在主Activity中,采用InstrumentedActivity侧边栏的方式,侧边栏的每一项对应一个Fragment,要实现不同的Fragment动态显示与隐藏ActionBar Me ...

  7. 如何删除textarea的移动版Safari的阴影?

    如何删除textarea的移动版Safari的阴影? 在iphone的Safari上运行网页,textarea无法使用box-shadow样式,而且顶部有内阴影,如何清除? 添加评论 分享   赞同1 ...

  8. 商派shopex

    http://www.shopex.cn/48release/shopexsingle_exper.php 在线体验 前台体验:http://demo.shopex.com.cn/485 后台体验:h ...

  9. Windows搭建SMTP邮件服务器

    From:http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-b ...

  10. TCP快速重传和快速恢复

    当tcp传送一个分组时会设置一个定时器,如果在规定的实际间隔内没有收到ACK分组,那么则重新传输该分组,但是 如果tcp收到三个连续的ACK分组,此时不管是否过超时间隔则重传该分组,具体步骤如下: 1 ...