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
#define MAX 1000000007 | |
#define FACT_MAX 250 | |
int add(int a, int b){ | |
return (a + b) % MAX; | |
} | |
int mul(int a, in b){ | |
return ((long long)a * b) % MAX; | |
} |
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
#define C_MAX 250 | |
int C[C_MAX][C_MAX]; | |
C[0][0] = 1; | |
for (int i = 1; i < C_MAX; i++){ | |
C[i][0] = 1; | |
for (int j = 1; j <= i; j++){ | |
/* Actual Binomial Coefficient */ | |
//C[i][j] = C[i-1][j] + C[i-1][j-1]; |
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
bool is_power_of_two(int n){ | |
return x && !(x & (x - 1)); | |
} |
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
void swap(int & a, int & b){ | |
a = a ^ b; | |
b = a ^ b; | |
a = a ^ b; | |
} |
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
int diff = 0; | |
for (int i = 0; i <= n; i++){ | |
if (B[diff + n] == -1) B[diff + n] = i; | |
else B[diff+ n] = min(B[diff + n], i); | |
if (C[diff + n] == -1) C[diff + n] = i; | |
else C[diff + n] = max(C[diff + n], i); | |
if (i < n && A[i] == 0) diff--; |
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 <iostream> | |
static const int N = 10000; | |
int main() | |
{ int i, j, p, q, id[N], sz[N]; | |
for (i = 0; i < N; i++) | |
{ id[i] = i; sz[i] = 1; } | |
while (cin >> p >> q) | |
{ |
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
int diff = 0; | |
for (int i = 0; i <= n; i++){ | |
if (B[diff + n] == -1) B[diff + n] = i; | |
else C[diff + n] = i; | |
if (A[i]) diff++; else diff--; | |
} |
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
int finished = 0; /* found all solutions yet? */ | |
template <class T> | |
backtrack(int a[], int k, T * input) | |
{ | |
T c[MAXCANDIDATES]; /* candidates for next position */ | |
int ncandidates; /* next position candidate count */ | |
int i; /* counter */ | |
if (is_a_solution(a,k,input)) |
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
prime_factorization(long x) | |
{ | |
long i; /* counter */ | |
long c; /* remaining product to factor */ | |
c = x; | |
while ((c % 2) == 0) { | |
printf("%ld\n",2); | |
c = c / 2; | |
} | |
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 <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
int n; | |
cin>>n; | |
int * A = new int[n]; | |
for (int i = 0; i < n; i++) A[i] = i + 1; |
OlderNewer