diff --git a/CP/January Lunchtime 2018/prob1.py b/CP/January Lunchtime 2018/prob1.py new file mode 100644 index 0000000..e69de29 diff --git a/CP/JanuaryCookOff2018/prob3-dp.cpp b/CP/JanuaryCookOff2018/prob3-dp.cpp new file mode 100644 index 0000000..15fce37 --- /dev/null +++ b/CP/JanuaryCookOff2018/prob3-dp.cpp @@ -0,0 +1,118 @@ +#include + +using namespace std; +typedef long long int ll; +const ll inf=pow(10,14); +bool apply(ll x,ll y,ll op) +{ +if(op==0) +{ +return xy; +} + +bool apply2(ll x,ll y,ll op) +{ +if(op==1) +{ +return xy; +} + +int main(){ + + ll t; +cin>>t; +while(t--) +{ +ll n,arr[100005]; +cin>>n; +for(ll i=0;i>arr[i]; + +ll dp[100005][2]; +for(ll i=0;i<100005;i++) +{ +for(ll j=0;j<2;j++) +dp[i][j]=inf; +} + +if(n==2) +{ +if(arr[0]==arr[1]) +cout<<-1<pow(10,12)) +cout<<-1< +using namespace std; + +const int N = 1005; + +int A[N][N]; +vector adj[N]; +bool visited[N]; +int ans[N][N]; +bool myParity[N]; + +int p[N], sz[N]; + +int par(int x){ + if(p[x] != x) p[x] = par(p[x]); + return p[x]; +} + +void join(int a, int b){ + int p1 = par(a), p2 = par(b); + if(p1 == p2) return ; + if(sz[p2] > sz[p1]) swap(p1, p2); + sz[p1] += sz[p2]; + p[p2] = p1; +} + +bool BipartiteCheck(int u, int parity) { + visited[u] = 1; + myParity[u] = parity; + for(auto v : adj[u]) { + if(A[u][v] == 1) continue; + if(visited[v] == 1 and myParity[v] == myParity[u]) return 0; + } + for(auto v : adj[u]){ + if(visited[v] == 1 or A[u][v] == 1) continue; + if(BipartiteCheck(v, parity^1) == 0) return 0; + } + return 1; +} + +void dfs_assign(int u, int val, int col_number) { + visited[u] = 1; + ans[u][col_number] = val; + for(auto v : adj[u]) { + if(visited[v]) continue; + dfs_assign(v, val * A[u][v], col_number); + } +} + +void solve() { + int n; + scanf("%d", &n); + //assert(n >= 1 and n <= 1000); + for(int i = 1; i <= n; i++) { + for(int j = 1; j <= n; j++) { + scanf("%d", &A[i][j]); + assert(A[i][j] >= -1 and A[i][j] <= 1); + } + } + + for(int i = 1; i <= n; i++) { + p[i] = i, sz[i] = 1; + visited[i] = 0; + adj[i].clear(); + for(int j = 1; j <= n; j++) ans[i][j] = 0; + } + + for(int i = 1; i <= n; i++) { + for(int j = 1; j <= n; j++) { + if(A[i][j] != A[j][i]) { + cout<<-1<