描述

Consider an ordered set S of strings of N (1 <= N <= 31) bits. Bits, of course, are either 0 or 1.

This set of strings is interesting because it is ordered and contains all possible strings of length N that have L (1 <= L <= N) or fewer bits that are `1'.

Your task is to read a number I (1 <= I <= sizeof(S)) from the input and print the Ith element of the ordered set for N bits with no more than L bits that are `1'.

输入

A single line with three space separated integers: N, L, and I.

输出

A single line containing the integer that represents the Ith element from the order set, as described.

样例输入

5 3 19

样例输出

10011

题意

N位的二进制串,从小到大排序,问'1'的个数<=L的第I个串。

题解

采用逐位确定法,如果要第N位填上'1',那么前N-1位<=L的串的个数<=I。

那么如何确定前N-1位<=L的串的个数呢?

dp[i][j]代表第i位填了j个'1'的串的个数,

当第i位填'1',那么就有dp[i-1][j-1]。

当第i位填‘0’,那么就有dp[i-1][j]。

代码

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[][],I;
int main()
{
int N,L;
cin>>N>>L>>I;
dp[][]=;
for(int i=;i<=N;i++)
for(int j=;j<=L;j++)
if(j==)dp[i][j]=dp[i-][j];
else if(j>i)dp[i][j]=dp[i][i];
else if(j==i)dp[i][j]=dp[i][j-]+;
else dp[i][j]=dp[i-][j]+dp[i-][j-];
for(int i=N-;i>=;i--)
if(dp[i][L]<I){cout<<"";I-=dp[i][L--];}
else cout<<"";
if(I!=)cout<<"";
else cout<<"";
return ;
}

TZOJ 5094 Stringsobits(DP)的更多相关文章

  1. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  2. 【USACO 3.2】Stringsobits (dp)

    题意:求第k大的最多有l个1的n位二进制. 题解:dp[i][j]表示长度为i最多有j个1的二进制有多少种,则有: 状态转移:dp[i][j]=dp[i-1][j]+dp[i-1][j-1],即第i位 ...

  3. TZOJ 2289 Help Bob(状压DP)

    描述 Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite ...

  4. TZOJ 5101 A Game(区间DP)

    描述 Consider the following two-player game played with a sequence of N positive integers (2 <= N & ...

  5. TZOJ 3295 括号序列(区间DP)

    描述 给定一串字符串,只由 “[”.“]” .“(”.“)”四个字符构成.现在让你尽量少的添加括号,得到一个规则的序列. 例如:“()”.“[]”.“(())”.“([])”.“()[]”.“()[( ...

  6. TZOJ 1800 Martian Mining(二维dp)

    描述 The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the A ...

  7. TZOJ 1937 Hie with the Pie(floyd+状压dp)

    描述 The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfo ...

  8. TZOJ 4912 炮兵阵地(状压dp)

    描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P" ...

  9. TZOJ 1545 Hurdles of 110m(01背包dp)

    描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperit ...

随机推荐

  1. 16.ajax_case06

    # 抓取华尔街见闻实时快讯 # https://wallstreetcn.com/live/global?from=navbar import requests import json header ...

  2. Java中方法的定义与使用,以及对数组的初步了解。

    方法 方法的含义 定义: 方法就是用来完成解决某件事情或实现某个功能的办法. 方法实现的过程中,会包含很多条语句用于完成某些有意义的功能——通常是处理文本,控制输入或计算数值. 我们可以通过在程序代码 ...

  3. spring mvc文件上传报错:Expected MultipartHttpServletRequest: is a MultipartResolver configured?

    报错原因:spring-mvc.xml 的配置文件中,配置文件上传id不为 “multipartResolver” 解决:id 改为 “multipartResolver”

  4. java笔试之完全数计算

    完全数(Perfect number),又称完美数或完备数,是一些特殊的自然数. 它所有的真因子(即除了自身以外的约数)的和(即因子函数),恰好等于它本身. 例如:28,它有约数1.2.4.7.14. ...

  5. 2018-8-10-win10-uwp-如何判断一个对象被移除

    title author date CreateTime categories win10 uwp 如何判断一个对象被移除 lindexi 2018-08-10 19:16:50 +0800 2018 ...

  6. kali linux 入门(1) 基于win10和docker的环境搭建

    1. 前言 渗透测试并没有一个标准的定义.国外一些安全组织达成共识的通用说法是,渗透测试是通过模拟恶意黑客的攻击方法,来评估计算机网络系统安全的一种评估方法,这个过程包括对系统的任何弱点.技术缺陷或漏 ...

  7. Luogu P2484 [SDOI2011]打地鼠(模拟+前缀和)

    P2484 [SDOI2011]打地鼠 题意 题目描述 打地鼠是这样的一个游戏:地面上有一些地鼠洞,地鼠们会不时从洞里探出头来很短时间后又缩回洞中.玩家的目标是在地鼠伸出头时,用锤子砸其头部,砸到的地 ...

  8. 数组(Array)与 字符串(String)公用的属性与方法

    数组与字符串都有很多方法,有一些方法是公用的,在这里就将数组与字符串公用的方法提取出来,方便大家的记忆 1. length 可通过str.length与arr.length分别取到字符串与数组的长度: ...

  9. 【BZOJ4561】[JLoi2016]圆的异或并

    传送门 把圆拆成上下两个圆弧,因为不存在相交关系,圆弧直接的上下关系是不变的. 用set维护这些圆弧,插入的时候upper_bound一下,如果找到的是上圆弧,就是我外面的第一个圆,否则我外面的第一个 ...

  10. Android HttpClient 用法以及乱码解决

    一.Post提交 并可以实现多文件上传 // 创建DefaultHttpClient对象 HttpClient httpclient = new DefaultHttpClient(); // 创建一 ...