wust 1419 1419: We Love 01( 计数问题)
来源:互联网 发布:淘宝店如何加入返利网 编辑:程序博客网 时间:2024/06/06 20:17
1419: We Love 01
Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: 30 Accepted: 7
[Submit][Status][Web Board]
Description
You have N ‘1’ and M ‘0’. You can use all of them to construct a binary number. For example you have 2 ‘1’ and 2 ‘0’. You can get 6 numbers “0110” “1100” “1010” “0011” “0101” “1001”.
Now, the problem is what’s the K-th smallest number?
Input
First line contains a number T, represent the number of test case.
Each case contains 3 numbers N M and K.
Output
For each case, output the K-th smallest number.
Sample Input
32 2 33 2 41 2 4
Sample Output
0110
01110
Impossible
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8//typedef __int64 ll;#define fre(i,a,b) for(i = a; i <b; i++)#define free(i,b,a) for(i = b; i >= a;i--)#define mem(t, v) memset ((t) , v, sizeof(t))#define ssf(n) scanf("%s", n)#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define bug pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 55int c[N][N];void inint(){int i,j;fre(i,0,N) fre(j,0,i+1) if(j==0||i==j) c[i][j]=1; else c[i][j]=c[i-1][j-1]+c[i-1][j];}void dfs(int n,int m,int k){ int i,j; if(n==0) { fre(i,0,m) pf("1"); return ; } if(m==0) { fre(i,0,n) pf("0"); return ; } int temp=c[n+m-1][m]; if(temp>=k) { pf("0"); dfs(n-1,m,k); } else { pf("1"); dfs(n,m-1,k-temp); }}int main(){int i,j,n,m,k,t;inint();sf(t);while(t--){sfff(m,n,k);if(c[n+m][m]<k){pf("Impossible\n");continue;} dfs(n,m,k); pf("\n");} pf("\n");}/*32 2 33 2 41 2 4*/
0 0
- wust 1419 1419: We Love 01( 计数问题)
- wust D we love design
- WUST OJ 1421 we love girl(贪心或DP)
- wust 1420 We love FibonaQ(矩阵+线段树)
- Why we love who we love (太长了,等我有时间再翻吧)
- We Love MOE Girls
- We Love MOE Girls
- HDU4730--We Love MOE Girls HDU(148)
- HDU-#4730 We Love MOE Girls(字符串)
- C - We Love MOE Girls---(2015 summer training #9)
- Why we love who we love 打破砂锅爱到底
- 打破砂锅爱到底Why we love who we love
- hdu--We Love MOE Girls
- hdu4730 We Love MOE Girls
- D-We Love MOE Girls
- HDU4730-We Love MOE Girls
- hdu4730 We Love MOE Girls
- [4730]:We Love MOE Girls
- 40个Java集合面试问题和答案
- libevent源码分析
- 矩阵嵌套问题(DAG上的动态规划)
- POJ 3009
- UVA10003---Cutting Sticks(简单区间dp)
- wust 1419 1419: We Love 01( 计数问题)
- Ajax传递数组,struts2接收数组
- MVC核心文件Application.class.php设计实例
- (10.2.3.5)用windows体验sketch--为设计师准备的MAC OS安装指南
- 工作中的学习与问题
- PLSQL Developer 连接Oracle 11g
- maven工程pom.xml文件讲解
- iOS开发系列--并行开发其实很容易
- Java加密技术介绍