TZOJ 5094 Stringsobits(DP)
描述
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)的更多相关文章
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- 【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位 ...
- TZOJ 2289 Help Bob(状压DP)
描述 Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite ...
- TZOJ 5101 A Game(区间DP)
描述 Consider the following two-player game played with a sequence of N positive integers (2 <= N & ...
- TZOJ 3295 括号序列(区间DP)
描述 给定一串字符串,只由 “[”.“]” .“(”.“)”四个字符构成.现在让你尽量少的添加括号,得到一个规则的序列. 例如:“()”.“[]”.“(())”.“([])”.“()[]”.“()[( ...
- TZOJ 1800 Martian Mining(二维dp)
描述 The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the A ...
- TZOJ 1937 Hie with the Pie(floyd+状压dp)
描述 The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfo ...
- TZOJ 4912 炮兵阵地(状压dp)
描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P" ...
- 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 ...
随机推荐
- Python第二课-输入输出
name = input() 输入的字符串已经赋值给变量name print() 输出内容 print(,) print中,连接字符串相当于空格
- P3338 [ZJOI2014]力 /// FFT 公式转化翻转
题目大意: https://www.luogu.org/problemnew/show/P3338 题解 #include <bits/stdc++.h> #define N 300005 ...
- sparkStreaming入门
1.环境 jdk : 1.8 scala : 2.11.7 hadoop:2.7 spark : 2.2.0 2. 开发工具 idea 2017.2 3.maven的pom文件 <depende ...
- Mybatis 动态insert动态插入的坑
在写insert子句的时候,由于不知道需要插入多少字段,mybatis通过prefix,suffix,suffixOverrides很好的解决了该问题,实现了动态insert语句. 用这种动态插入时& ...
- QSerialPort类
一.简介 QSerialPort类是Qt5封装的串口类,可以与串口进行通信.QSerialPortInfo是一个辅助类,提供串口的一些信息,如可用的串口名称,描述,制造商,序列号,串口16位产 ...
- python requests 高级用法 -- 包括SSL 证书错误的解决方案
Session Objects会话对象 Session对象在请求时允许你坚持一定的参数.此外,还坚持由Session实例的所有请求的cookie. 让我们坚持在请求时使用 s = requests.S ...
- 【JZOJ3303】城市规划
description 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n 个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得整个国家的任意两个城市都直接 ...
- 廖雪峰Java15JDBC编程-2SQL入门-1SQL介绍
1.SQL:结构化查询语言 Structured Query Language 针对关系数据库设计 各种数据库基本一致 允许用户通过SQL查询数据而不关心数据库底层存储结构 1.1 SQL使用: 可以 ...
- thinkphp 组合查询
组合查询的主体还是采用数组方式查询,只是加入了一些特殊的查询支持,包括字符串模式查询(_string).复合查询(_complex).请求字符串查询(_query),混合查询中的特殊查询每次查询只能定 ...
- hibernate 映射总结
单向一对多实体配置:在一的实体中设置多的一方SET集合配置文件:在一的一方用set 设置 one to many表配置:多方表的外键指向一方表的主键; 双向一对多实体配置:在一的实体中设置多的一方SE ...