描述

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. 3.在vm上安装centos 7

    在vm上安装centos 7 1.文件 → 新建虚拟机 3.选择安装Linux系统 4. 虚拟机命名,并选择安装的文件夹 5.选择分配的处理器 6.使用网络地址转换 7.默写选项 9.新建虚拟机 10 ...

  2. netty 解决粘包拆包问题

    netty server TimeServer package com.zhaowb.netty.ch4_3; import io.netty.bootstrap.ServerBootstrap; i ...

  3. mysql权限修改记录

    select user, password, host from mysql.user; GRANT ALL PRIVILEGES ON *.* TO 'root'@'147.114.169.197' ...

  4. 锋利的Jquery(p的onclick()事件)

    1.一个p元素的点击事件 <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="serve ...

  5. 【默默努力】vue-pc-app

    最近在github上面看到了一个团队的项目,真的非常赞.他们进行vue-cli的二次开发,将项目用自己的方式打包. 今天的这个开源项目地址为:https://github.com/tffe-team/ ...

  6. Django流程

    开始具体的代码之旅前,先来宏观地看下Django是如何处理Http Resquest的,如下图: 假设你已经在浏览器输入了 http://127.0.0.1:8000/polls/,接下来浏览器会把请 ...

  7. [转]WPF的BitmapImage的文件无法释放及内存泄露的问题

    相信用过WPF的BitmapImage的,都在用类似这样的代码来解决文件无法删除的问题! 如果看看msdn上简单的描述,可以看到这样的说明: 如果 StreamSource 和 UriSource 均 ...

  8. day04 - linux常用命令、目录说明以及ubuntu解锁root用户,安装tree命令

    echo abcdefg >> aa.txt //向aa.txt文件末尾追加 abcdefg 字符串 1 基础命令: clear //清屏 whoami //查看当前所登录的用户 who ...

  9. 第十二章 Odoo 12开发之报表和服务端 QWeb

    报表是业务应用非常有价值的功能,内置的 QWeb 引擎是报表的默认引擎.使用 QWeb 模板设计的报表可生成 HTML 文件并被转化成 PDF.也就是说我们可以很便捷地利用已学习的 QWeb 知识,应 ...

  10. 为WCF增加UDP绑定(实践篇)

    这两天忙着系统其它功能的开发,没顾上写日志.本篇所述皆围绕为WCF增加UDP绑定(储备篇)中讲到的微软示例,该示例我已上传到网盘. 上篇说道,绑定是由若干绑定元素有序组成,为WCF增加UDP绑定其实就 ...