forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetRow.cpp
More file actions
35 lines (32 loc) · 775 Bytes
/
getRow.cpp
File metadata and controls
35 lines (32 loc) · 775 Bytes
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
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long LL;
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res(rowIndex + 1);
res[0] = 1;
FOR(i,1,rowIndex) {
vector<int> t(rowIndex + 1);
t[0] = res[0];
t[i] = res[i - 1];
FOR(j,1,i-1) t[j] = res[j - 1] + res[j];
res = t;
}
return res;
}
};
int main() {
Solution s;
REP(i,6) {
vector<int> res = s.getRow(i);
REP(j,res.size()) cout << res[j] << " ";
cout << endl;
}
return 0;
}