构造
看成k进制的d位数。。
1 n,k,d = map(int, raw_input().split()) 2 if n > k**d: print -1 3 else: 4 ans = [] 5 for i in range(n): 6 tmp = i 7 cur = [] 8 for j in range(d): 9 cur.append(tmp%k+1) 10 tmp /= k 11 ans.append(cur) 12 for i in range(d): 13 for j in ans: 14 print j[i], 15 print ''
D.http://codeforces.com/contest/459/problem/D
树状数组求逆序数
没怎么看懂思路。。噗。。
参考:http://www.cnblogs.com/yuiffy/p/3916512.html
E.http://codeforces.com/contest/459/problem/E
1 /*Author :usedrose */ 2 /*Created Time :2015/8/9 21:56:08*/ 3 /*File Name :2.cpp*/ 4 #pragma comment(linker, "/STACK:1024000000,1024000000") 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <sstream> 9 #include <cstdlib> 10 #include <cstring> 11 #include <climits> 12 #include <vector> 13 #include <string> 14 #include <ctime> 15 #include <cmath> 16 #include <deque> 17 #include <queue> 18 #include <stack> 19 #include <set> 20 #include <map> 21 #define INF 0x3f3f3f3f 22 #define eps 1e-8 23 #define pi acos(-1.0) 24 #define MAXN 1110 25 #define MAXM 300110 26 #define OK cout << "ok" << endl; 27 #define o(a) cout << #a << " = " << a << endl 28 #define o1(a,b) cout << #a << " = " << a << " " << #b << " = " << b << endl 29 using namespace std; 30 typedef long long LL; 31 32 struct node { 33 int u, v, w; 34 bool operator<(const node& ss) const { 35 return w < ss.w; 36 } 37 }e[MAXM]; 38 int n, m; 39 int dp[MAXM], g[MAXM]; 40 41 int main() 42 { 43 cin.tie(0); 44 ios::sync_with_stdio(false); 45 cin >> n >> m; 46 for (int i = 0;i < m; ++ i) 47 cin >> e[i].u >> e[i].v >> e[i].w; 48 sort(e, e + m); 49 int t = 0, ans = 0; 50 for (int i = 0;i < m; ++ i) { 51 dp[i] = g[e[i].u] + 1; 52 if (e[i].w != e[i+1].w) { 53 for (int j = t; j <= i; ++ j) 54 g[e[j].v] = max(dp[j], g[e[j].v]); 55 t = i+1; 56 } 57 ans = max(ans, dp[i]); 58 } 59 cout << ans << endl; 60 return 0; 61 }
参考
http://blog.csdn.net/y990041769/article/details/38709519