USACO Section 3.2: Stringsobits

这题看了网上的答案的。还是很巧妙的

 1 /*

 2 ID: yingzho1

 3 LANG: C++

 4 TASK: kimbits

 5 */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <stdio.h>

14 #include <queue>

15 #include <cstring>

16 #include <cmath>

17 #include <list>

18 #include <cstdio>

19 #include <cstdlib>

20 

21 using namespace std;

22 

23 ifstream fin("kimbits.in");

24 ofstream fout("kimbits.out");

25 

26 const int inf = 100000000;

27 

28 int N, L;

29 long long I;

30 

31 int main()

32 {

33     fin >> N >> L >> I;

34     vector<vector<long long> > f(N+1, vector<long long>(N+1));

35     for (int i = 0; i <= N; i++) f[i][0] = 1;

36     for (int i = 1; i <= N; i++) {

37         for (int j = 1; j <= i; j++) {

38             f[i][j] = f[i-1][j-1] + f[i-1][j];

39         }

40     }

41     for (int i = 0; i <= N; i++) {

42         for (int j = 1; j <= N; j++) {

43             f[i][j] += f[i][j-1];

44         }

45     }

46     for (int i = N; i >= 1; i--) {

47         if (f[i-1][L] >= I) fout << "0";

48         else {

49             fout << "1";

50             I -= f[i-1][L--];

51         }

52     }

53     fout << endl;

54 

55     return 0;

56 }

 

你可能感兴趣的:(String)