forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_simulation_n2.cpp
45 lines (38 loc) · 916 Bytes
/
AC_simulation_n2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n2.cpp
* Create Date: 2014-12-15 15:00:00
* Descripton:
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<vector<int> > ans(2);
ans[0&1].push_back(1);
if (rowIndex == 0)
return ans[0&1];
for (int i = 1; i <= rowIndex; i++) {
ans[i&1].clear();
ans[i&1].push_back(1);
for (int j = 1; j < i; j++)
ans[i&1].push_back(ans[!(i&1)][j - 1] + ans[!(i&1)][j]);
ans[i&1].push_back(1);
}
return ans[rowIndex&1];
}
};
int main() {
int n;
Solution s;
while (cin >> n) {
vector<int> v;
v = s.getRow(n);
for (int i : v)
printf("%d ", i);
puts("");
}
return 0;
}