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的更多相关文章

随机推荐

  1. CS6的安装与破解

    大家在Mac下肯定也少不了对图片进行修改,那也就少不了Photoshop这款软件. 今天在这里分享下苹果下的Adobe PhotoshopCS6,这个软件大家应该都很熟悉,主要功能什么我就不多做介绍了 ...

  2. bzoj1069-最大土地面积

    题目 给定\(n\ (n\le 2000)\)个坐标,求四个坐标使得围起来的四边形面积最大. 分析 最暴力的想法是枚举四个点,然而肯定超时.接着不知道怎么想到中途相遇,然而一点关系都没有.这里用到了一 ...

  3. Javascript基础之-强制类型转换(二)

    思考下面这个问题: console.log(+"123"); // 123 console.log(-"123"); // -123 console.log(+ ...

  4. BZOJ1926:[SDOI2010]粟粟的书架——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1926 https://www.luogu.org/problemnew/show/P2468 幸福幼 ...

  5. 洛谷 P2898 [USACO08JAN]haybale猜测Haybale Guessing 解题报告

    [USACO08JAN]haybale猜测Haybale Guessing 题目描述 给一段长度为\(n\),每个位置上的数都不同的序列\(a[1\dots n]\)和\(q\)和问答,每个问答是\( ...

  6. Ubuntu16.04+Cuda8.0+1080ti+caffe+免OpenCV3.2.0+faster-rCNN教程

    一.事先声明:1.Ubuntu版本:Ubuntu使用的是16.04.而不是16.04.1或16.04.2,这三个是有区别的.笔者曾有过这样的经历,Git上一个SLAM地图构建程序在Ubuntu14.0 ...

  7. maven的tomcat插件如何进行debug调试

    利用maven来部署工程时,一般采用的是tomcat插件,使项目在tomcat上面运行,那么这个debug调试是如何进行呢? 我们在调试的时候问题: 会提示找不到资源,那么如何进行修改呢,方法两个: ...

  8. [lottery anayliser]lottery anayliser

    抓取网页,获得获奖信息 #!/usr/bin/python import urllib2 import re import time def spider(url): ""&quo ...

  9. HDU 5533Dancing Stars on Me 基础几何

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  10. POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...