kimbits_USACO
Stringsobits
Kim Schrijvers
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'.
PROGRAM NAME: kimbits
INPUT FORMAT
A single line with three space separated integers: N, L, and I.
SAMPLE INPUT (file kimbits.in)
5 3 19
OUTPUT FORMAT
A single line containing the integer that represents the Ith element from the order set, as described.
SAMPLE OUTPUT (file kimbits.out)
10011
题意:考虑排好序的N(N<=31)位二进制数。他们是排列好的,而且包含所有长度为N且这个二进制数中1的位数的个数小于等于L(L<=N)的数。你的任务是输出第i(1<=i<=长度为N的二进制数的个数)小的(注:题目这里表述不清,实际是,从最小的往大的数,数到第i个符合条件的,这个意思),长度为N,且1的位数的个数小于等于L的那个二进制数。(例:100101中,N=6,含有位数为1的个数为3)。
此题 I 最大值会爆int,= =
dp[i][j] 表示 i位的含j个1的二进制数个数,dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
/*
ID: LinKArftc
PROG: kimbits
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ; ll dp[maxn][maxn]; //dp[i][j]: i位的含j个1的二进制数个数
int n, l;
ll k; void init() {
dp[][] = dp[][] = dp[][] = ;
for (int i = ; i < maxn; i ++) {
dp[i][] = ;
for (int j = ; j < maxn; j ++) dp[i][j] = dp[i-][j] + dp[i-][j-];
}
} int main() {
freopen("kimbits.in", "r", stdin);
freopen("kimbits.out", "w", stdout);
init();
scanf("%d %d %lld", &n, &l, &k);
for (int i = ; i <= n; i ++) {
if (l == ) {
printf("");
continue;
}
ll sum = ;
for (int j = ; j <= l; j ++) {
sum += dp[n-i][j];
}
if (k <= sum) printf("");
else {
printf("");
l --;
k -= sum;
}
}
printf("\n");
return ;
}
kimbits_USACO的更多相关文章
随机推荐
- WPF如何将数据库中的二进制图片数据显示在Image控件上
首先在xaml文件里定义一个Image控件,取名为img MemoryStream stream = new MemoryStream(获得的数据库对象): BitMapImage bmp = new ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- POJ3907:Build Your Home——题解
http://poj.org/problem?id=3907 题目大意:求多边形面积,结果四舍五入. ———————————————————— 多边形面积公式板子题. #include<cstd ...
- BZOJ1507 [NOI2003]Editor 【splay】
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MB Submit: 4129 Solved: 1660 [Submit][St ...
- mysql 读写分离实现资料
以下很多链接需要 FQ才能看到,稍后会整理翻译成中文! Easy Read/Write Splitting with PHP’s MySQLnd https://blog.engineyard.com ...
- IE9的大css文件截断问题
最近做项目调试IE9的兼容性,遇到问题,样式应用不上去,在其他浏览器中是正常的. 经过查找,判定是IE9的css截断问题. 1. IE9截断判定方法 1. 打开IE Developer Tools,在 ...
- JavaScript非阻塞加载脚本
As more and more sites evolve into “Web 2.0″ apps, the amount of JavaScript increases. This is a per ...
- HDU2647 topsort
Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he ...
- Leetcode 94. 二叉树的中序遍历
1.问题描述 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 2.解法一 ...
- sql 语句 插入数据 返回值问题
1. 主键ID 自增 ,插入数据后返回这条数据的ID值 insert into tableName() values() select @@identity 2.主键ID 使用GUID类型值 ,插入数 ...