forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_dp_nm.cpp
39 lines (33 loc) · 853 Bytes
/
AC_dp_nm.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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_dp_nm.cpp
* Create Date: 2014-12-27 09:07:32
* Descripton: dp
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
int uniquePaths(int m, int n) {
// way 1
// vector<vector<int> > tab(2, vector<int>(n + 1, 1));
// for (int i = 1; i < m; i++)
// for (int j = 1; j < n; j++)
// tab[i&1][j] = tab[!(i&1)][j] + tab[i&1][j - 1];
// return tab[(m-1)&1][n - 1];
vector<int> tab(n, 1);
for (int i = 1; i < m; i++)
for (int j = 1; j < n; j++)
tab[j] += tab[j - 1];
return tab[n - 1];
}
};
int main() {
int n, m;
Solution s;
while (cin >> n >> m) {
cout << s.uniquePaths(n, m);
}
return 0;
}