Untitled
unknown
plain_text
16 days ago
1.7 kB
2
Indexable
Never
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include <set> #include <stack> #include <iomanip> #include <cmath> #include <cstring> #include <numeric> #include <cstdio> #include <list> #include <cassert> #include <climits> #include <bitset> using namespace std; #define IN(type, name) \ type name; \ cin >> name; #define For(var, constant, init) for (int var = init; var < constant; var++) #define Sp << ' ' << #define End << '\n' #define PI 3.141592653589793238462643383279502884L #define ll long long #define ull unsigned long long #define uint unsigned int #define ld long double #define MOD 1000000007 typedef vector<int> vint; typedef vector<ll> vll; typedef pair<int, int> pint; typedef pair<ll, ll> pll; int n, r; vector<string> v; vector<string> out; void rec(int len, int index, string crnt) { if (len == r) { out.push_back(crnt); return; } if (index == n) return; rec(len, index+1, crnt); rec(len + 1, index+1, crnt + to_string(index)); } bool strComp(string &s1, string &s2) { int len1 = s1.length(), len2 = s2.length(); int len = min(len1, len2); For(i, len, 0) { if (s1[i] < s2[i]) return true; else if (s1[i] > s2[i]) return false; else continue; } return (len1 < len2); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> r; v.resize(n); For(i,n,0) cin >> v[i]; sort(v.begin(), v.end(), strComp); rec(0, 0, ""); sort(out.begin(), out.end(), strComp); for(string &s : out) { for(char &c : s) cout << v[c - '0'] << ' '; cout End; } }
Leave a Comment