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的更多相关文章
随机推荐
- Devc++编译系统分配给int多少字节
我看的是<C语言程序设计>..谭浩强的PDF版 里面只讲了VC和TC 的,没有Devc++的..(我的是5.10版) 还有这是什么意思? 经过查阅我进行了这样的测试: 得到了这样的结果: ...
- 【刷题】洛谷 P2764 最小路径覆盖问题
题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...
- Android 通知机制 Toast和Notification
Android常用的反馈系统状态信息的方式主要有三种 Toast提醒 通知栏提醒 对话框提醒 三种提醒分别适用于页面的提示.系统交互事件的通知和非常重要的提醒: 一.Toast Toast toast ...
- BZOJ1023:[SHOI2008]仙人掌图——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1023 Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple ...
- BZOJ3714 [PA2014]Kuglarz 【最小生成树】
题目链接 BZOJ3714 题解 我们如果知道了所有的数,同样就知道了所有的前缀和 相反,我们如果求出了所有前缀和,就知道了所有的数,二者是等价的 对于一个区间\([l,r]\)如果我们知道了前缀和\ ...
- BZOJ1027 [HNOI2004]打鼹鼠 【dp】
1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3647 Solved: 1746 [Submit][Sta ...
- HDOJ.2072 单词数(map)
单词数 点我挑战题目 点我一起学习STL-MAP 题意分析 给出一行单词,判断这行有不同种的单词多少个,用map可以轻松解决. 代码总览 /* Title:HDOJ.2072 Author:pengw ...
- 20181022 考试记录&高级数据结构
题目 W神爷的题解 高级数据结构 T1: 其实是一道easy题,$O(n^3log n)$ 也是能卡过去的,本着要的70分的心态,最后尽然A了. 如果是正解则是$O(n^3)$,当确定你要选择的列时, ...
- linux 小技巧
http://blog.csdn.net/xianjie0318/article/details/75712990 1.按内存从大到小排列进程: ps -eo "%C : %p : % ...
- javascript实用例子
js学习笔记,别错过!很有用的. /////////////////////////////////////////////////////////////////////////////////// ...