描述

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 ;
}

最新文章

  1. TouchPoint.js – 可视化展示 HTML 原型点击效果
  2. Linux内核设计第二周——操作系统工作原理
  3. Browser设置搜索引擎
  4. HTML5之结构元素
  5. visual asssit 过期提示
  6. fragment嵌套,viewpager嵌套 不能正确显示
  7. Oracle语句优化1
  8. C++各种指针辨析
  9. JS获取前天、昨天、今天、明天、后天的时间
  10. cocos2dx-lua中handler解析
  11. Qt学习2---信号与槽
  12. DP基础练习(4.21)
  13. 【2018.05.05 C与C++基础】C++中的自动废料收集:概念与问题引入
  14. JCR分区(WOS或Thomson Reuters或汤姆森 路透)和中科院分区(附网址及查询方法)
  15. javascript编写带阴历的黄历
  16. android 当ListView滚动时自动调用 onCheckedChanged 导致CheckBox 状态不停变化 的解决办法
  17. Maven命令行使用 mvn clean package
  18. Visual Studio最常用的快捷键
  19. C# 合并多个结构相同的DataTable
  20. jquery中的正则表达式

热门文章

  1. windows系统下jupyter notebook使用虚拟环境
  2. &lt;scrapy爬虫&gt;scrapy命令行操作
  3. Spring AspectJ 切入点语法详解(7)
  4. [WPF自定义控件库]使用WindowChrome自定义RibbonWindow
  5. NuGet 命令行使用EntityFrameWork
  6. dataset datatable 转json
  7. 记mysql 启动不了了的解决方法
  8. [转]成为Java顶尖程序员 ,看这11本书就够了
  9. TestNG 入门教程【转】
  10. 常用DOM API总结