Created
October 23, 2018 07:30
-
-
Save mikebsg01/45cd7c815f1742ae967745dd5722a066 to your computer and use it in GitHub Desktop.
Pascal's Triangle with Bitmasks (DP Solution)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define dd(x) cout << #x << ": " << x << endl; | |
#define MAXN 1000003 | |
#define MOD 1000000007 | |
using namespace std; | |
typedef long long int lli; | |
int N; | |
lli dp[2][MAXN]; | |
void pascal() { | |
int i, j, idx = 1; | |
dp[0][1] = 1; | |
for (i = 1; i <= N; ++i) { | |
for (j = 1; j <= (i + 1); ++j) { | |
dp[idx][j] = dp[idx ^ 1][j] + dp[idx ^ 1][j - 1]; | |
dp[idx][j] %= MOD; | |
} | |
idx ^= 1; | |
} | |
idx ^= 1; | |
for (i = 1; i <= (N + 1); ++i) { | |
if (i > 1) { | |
cout << ' '; | |
} | |
cout << dp[idx][i]; | |
} | |
cout << '\n'; | |
} | |
int main() { | |
cin >> N; | |
pascal(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment