Skip to content

Commit

Permalink
Added all currently solved problems
Browse files Browse the repository at this point in the history
  • Loading branch information
infinity4471 authored Nov 26, 2018
1 parent 80562c1 commit b4d4b32
Show file tree
Hide file tree
Showing 44 changed files with 1,391 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 107/large_case4.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
0 0 0 427 668 495 377 678 0 177 0 0 870 0 869 624 300 609 131 0 251 0 0 0 856 221 514 0 591 762 182 56 0 884 412 273 636 0 0 774
0 0 262 0 0 508 472 799 0 956 578 363 940 143 0 162 122 910 0 729 802 941 922 573 531 539 667 607 0 920 0 0 315 649 937 0 185 102 636 289
0 262 0 0 926 0 958 158 647 47 621 264 81 0 402 813 649 386 252 391 264 637 349 0 0 0 108 0 727 225 578 699 0 898 294 0 575 168 432 833
427 0 0 0 366 0 0 635 0 32 962 468 893 854 718 427 448 916 258 0 760 909 529 311 404 0 0 588 680 875 0 615 0 409 758 221 0 0 76 257
668 0 926 366 0 0 0 250 268 0 503 944 0 677 0 727 793 457 981 191 0 0 0 351 969 925 987 328 282 589 0 873 477 0 0 19 450 0 0 0
495 508 0 0 0 0 0 765 711 819 305 302 926 0 0 582 0 861 0 683 293 0 0 66 0 27 0 0 290 0 786 0 554 817 33 0 54 506 386 381
377 472 958 0 0 0 0 0 0 120 42 0 134 219 457 639 538 374 0 0 0 966 0 0 0 0 0 449 120 797 358 232 550 0 305 997 662 744 686 239
678 799 158 635 250 765 0 0 0 35 0 106 385 652 160 0 890 812 605 953 0 0 0 79 0 712 613 312 452 0 978 900 0 901 0 0 225 533 770 722
0 0 647 0 268 711 0 0 0 283 0 172 0 663 236 36 403 286 986 0 0 810 761 574 53 793 0 0 777 330 936 883 286 0 174 0 0 0 828 711
177 956 47 32 0 819 120 35 283 0 50 0 565 36 767 684 344 489 565 0 0 103 810 463 733 665 494 644 863 25 385 0 342 470 0 0 0 730 582 468
0 578 621 962 503 305 42 0 0 50 0 155 519 0 0 256 990 801 154 53 474 650 402 0 0 0 966 0 0 406 989 772 932 7 0 823 391 0 0 933
0 363 264 468 944 302 0 106 172 0 155 0 0 0 380 438 0 41 266 0 0 104 867 609 0 270 861 0 0 165 0 675 250 686 995 366 191 0 433 0
870 940 81 893 0 926 134 385 0 565 519 0 0 313 851 0 0 0 248 220 0 826 359 829 0 234 198 145 409 68 359 0 814 218 186 0 0 929 203 0
0 143 0 854 677 0 219 652 663 36 0 0 313 0 132 0 433 598 0 0 168 870 0 0 0 128 437 0 383 364 966 227 0 0 807 993 0 0 526 17
869 0 402 718 0 0 457 160 236 767 0 380 851 132 0 0 596 903 613 730 0 261 0 142 379 885 89 0 848 258 112 0 900 0 0 818 639 268 600 0
624 162 813 427 727 582 639 0 36 684 256 438 0 0 0 0 539 379 664 561 542 0 999 585 0 0 321 398 0 0 950 68 193 0 697 0 390 588 848 0
300 122 649 448 793 0 538 890 403 344 990 0 0 433 596 539 0 0 73 0 318 0 0 500 0 968 0 291 0 0 765 196 504 757 0 542 0 395 227 148
609 910 386 916 457 861 374 812 286 489 801 41 0 598 903 379 0 0 0 946 136 399 0 941 707 156 757 258 251 0 807 0 0 0 461 501 0 0 616 0
131 0 252 258 981 0 0 605 986 565 154 266 248 0 613 664 73 0 0 686 0 0 575 627 817 282 0 698 398 222 0 649 0 0 0 0 0 654 0 0
0 729 391 0 191 683 0 953 0 0 53 0 220 0 730 561 0 946 686 0 0 389 729 553 304 703 455 857 260 0 991 182 351 477 867 0 0 889 217 853
251 802 264 760 0 293 0 0 0 0 474 0 0 168 0 542 318 136 0 0 0 0 392 0 0 0 267 407 27 651 80 927 0 974 977 0 0 457 117 0
0 941 637 909 0 0 966 0 810 103 650 104 826 870 261 0 0 399 0 389 0 0 0 202 0 0 0 0 867 140 403 962 785 0 511 0 1 0 707 0
0 922 349 529 0 0 0 0 761 810 402 867 359 0 0 999 0 0 575 729 392 0 0 388 939 0 959 0 83 463 361 0 0 512 931 0 224 690 369 0
0 573 0 311 351 66 0 79 574 463 0 609 829 0 142 585 500 941 627 553 0 202 388 0 164 829 0 620 523 639 936 0 0 490 0 695 0 505 109 0
856 531 0 404 969 0 0 0 53 733 0 0 0 0 379 0 0 707 817 304 0 0 939 164 0 0 616 716 728 0 889 349 0 963 150 447 0 292 586 264
221 539 0 0 925 27 0 712 793 665 0 270 234 128 885 0 968 156 282 703 0 0 0 829 0 0 0 822 0 0 0 736 576 0 697 946 443 0 205 194
514 667 108 0 987 0 0 613 0 494 966 861 198 437 89 321 0 757 0 455 267 0 959 0 616 0 0 0 349 156 339 0 102 790 359 0 439 938 809 260
0 607 0 588 328 0 449 312 0 644 0 0 145 0 0 398 291 258 698 857 407 0 0 620 716 822 0 0 293 486 943 0 779 0 6 880 116 775 0 947
591 0 727 680 282 290 120 452 777 863 0 0 409 383 848 0 0 251 398 260 27 867 83 523 728 0 349 293 0 212 684 505 341 384 9 992 507 48 0 0
762 920 225 875 589 0 797 0 330 25 406 165 68 364 258 0 0 0 222 0 651 140 463 639 0 0 156 486 212 0 0 349 723 0 0 186 0 36 240 752
182 0 578 0 0 786 358 978 936 385 989 0 359 966 112 950 765 807 0 991 80 403 361 936 889 0 339 943 684 0 0 965 302 676 725 0 327 134 0 147
56 0 699 615 873 0 232 900 883 0 772 675 0 227 0 68 196 0 649 182 927 962 0 0 349 736 0 0 505 349 965 0 474 178 833 0 0 555 853 0
0 315 0 0 477 554 550 0 286 342 932 250 814 0 900 193 504 0 0 351 0 785 0 0 0 576 102 779 341 723 302 474 0 689 0 0 0 451 0 0
884 649 898 409 0 817 0 901 0 470 7 686 218 0 0 0 757 0 0 477 974 0 512 490 963 0 790 0 384 0 676 178 689 0 245 596 445 0 0 343
412 937 294 758 0 33 305 0 174 0 0 995 186 807 0 697 0 461 0 867 977 511 931 0 150 697 359 6 9 0 725 833 0 245 0 949 0 270 0 112
273 0 0 221 19 0 997 0 0 0 823 366 0 993 818 0 542 501 0 0 0 0 0 695 447 946 0 880 992 186 0 0 0 596 949 0 91 0 768 273
636 185 575 0 450 54 662 225 0 0 391 191 0 0 639 390 0 0 0 0 0 1 224 0 0 443 439 116 507 0 327 0 0 445 0 91 0 248 0 344
0 102 168 0 0 506 744 533 0 730 0 0 929 0 268 588 395 0 654 889 457 0 690 505 292 0 938 775 48 36 134 555 451 0 270 0 248 0 371 680
0 636 432 76 0 386 686 770 828 582 0 433 203 526 600 848 227 616 0 217 117 707 369 109 586 205 809 0 0 240 0 853 0 0 0 768 0 371 0 540
774 289 833 257 0 381 239 722 711 468 933 0 0 17 0 0 148 0 0 853 0 0 0 0 264 194 260 947 0 752 147 0 0 343 112 273 344 680 540 0
Binary file added 107/prim
Binary file not shown.
71 changes: 71 additions & 0 deletions 107/prim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <cstdio>
#include <queue>
#include <vector>
#include <utility>
#include <functional>
#include <set>
#include <map>

using namespace std;

struct edges
{
int x;
int weight;
};

bool operator<(const edges& a,const edges& b)
{
return a.weight<b.weight?0:1;
}
int main(void)
{
freopen("large_case4.in","rt",stdin);
int V,E,u,v,w,min_weight=0;
E=40; V=40;
long sum=0;
vector<edges> graph[V+1];
priority_queue<edges> q;
edges p;
bool visited[V+1];
for(int i=1; i<=V; i++)
{
visited[i]=false;
}
for(int i=1; i<=E; i++)
{
for(int j=1; j<=E; j++)
{
scanf("%d",&w);
if(w==0)
continue;
p.x=j;
p.weight=w;
sum+=p.weight;
graph[i].push_back(p);
}
}
p.x=1;
p.weight=0;
q.push(p);
while(!q.empty())
{
p=q.top();
q.pop();
if(!visited[p.x])
{
min_weight+=p.weight;
visited[p.x]=true;
}
for(int i=0; i<graph[p.x].size(); i++)
{
if(!visited[graph[p.x].at(i).x])
{
printf("weight =%d starting edge = %d ending edge=%d\n",graph[p.x].at(i).weight,p.x,graph[p.x].at(i).x);
q.push(graph[p.x].at(i));
}
}
}
printf("%d\n",sum/2-min_weight);
return 0;
}
Binary file added 114/114
Binary file not shown.
25 changes: 25 additions & 0 deletions 114/114.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstdio>
#include <algorithm>

#define N 50

using namespace std;

// 0 -> black
// 1 -> red

int main( void )
{
long long dp[ N + 1 ][ 2 ];
dp[ 0 ][ 0 ] = 1;
dp[ 0 ][ 1 ] = 0;
for( int i = 1; i <= N; i++ ) {
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + dp[ i - 1 ][ 1 ];
dp[ i ][ 1 ] = 0;
for( int j = i - 3; j >= 0; j-- ) {
dp[ i ][ 1 ] += dp[ j ][ 0 ];
}
}
printf("%lld\n", dp[ N ][ 0 ] + dp[ N ][ 1 ] );
return 0;
}
Binary file added 114/a.out
Binary file not shown.
18 changes: 18 additions & 0 deletions 114/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h> /* for printf */
#include <gmp.h>

int main(int argc, char *argv[])
{
mpz_t a, b; /* working numbers */
if (argc<3)
{ /* not enough words */
printf("Please supply two numbers to add.\n");
return 1;
}
mpz_init_set_str (a, argv[1], 10); /* Assume decimal integers */
mpz_init_set_str (b, argv[2], 10); /* Assume decimal integers */
mpz_add (a, a, b); /* a=a+b */

printf("%s + %s => %s\n", argv[1], argv[2], mpz_get_str (NULL, 10, a));
return 0;
}
29 changes: 29 additions & 0 deletions 115/115.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <cstdio>
#include <algorithm>

#define N 200
#define M 50

using namespace std;

// 0 -> black
// 1 -> red

int main( void )
{
long long dp[ N + 1 ][ 2 ];
dp[ 0 ][ 0 ] = 1;
dp[ 0 ][ 1 ] = 0;
for( int i = 1;; i++ ) {
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + dp[ i - 1 ][ 1 ];
dp[ i ][ 1 ] = 0;
for( int j = i - M; j >= 0; j-- ) {
dp[ i ][ 1 ] += dp[ j ][ 0 ];
}
if( dp[ i ][ 0 ] + dp[ i ][ 1 ] > 1000000 ) {
printf("%d\n", i );
break;
}
}
return 0;
}
Binary file added 116/116
Binary file not shown.
45 changes: 45 additions & 0 deletions 116/116.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <cstdio>

#define N 50

typedef long long unsigned llu;

int main( void )
{
llu dp[ N + 1 ][ 2 ], ans = 0;
dp[ 0 ][ 0 ] = 1;
dp[ 0 ][ 1 ] = 0;
dp[ 1 ][ 0 ] = 1;
dp[ 1 ][ 1 ] = 0;
for( int i = 2; i <= N; i++ ) {
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + dp[ i - 1 ][ 1 ];
dp[ i ][ 1 ] = dp[ i - 2 ][ 0 ] + dp[ i - 2 ][ 1 ];
}
ans += dp[ N ][ 0 ] + dp[ N ][ 1 ] - 1;
dp[ 0 ][ 0 ] = 1;
dp[ 0 ][ 1 ] = 0;
dp[ 1 ][ 0 ] = 1;
dp[ 1 ][ 1 ] = 0;
dp[ 2 ][ 0 ] = 1;
dp[ 2 ][ 1 ] = 0;
for( int i = 3; i <= N; i++ ) {
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + dp[ i - 1 ][ 1 ];
dp[ i ][ 1 ] = dp[ i - 3 ][ 0 ] + dp[ i - 3 ][ 1 ];
}
ans += dp[ N ][ 0 ] + dp[ N ][ 1 ] - 1;
dp[ 0 ][ 0 ] = 1;
dp[ 0 ][ 1 ] = 0;
dp[ 1 ][ 0 ] = 1;
dp[ 1 ][ 1 ] = 0;
dp[ 2 ][ 0 ] = 1;
dp[ 2 ][ 1 ] = 0;
dp[ 3 ][ 0 ] = 1;
dp[ 3 ][ 1 ] = 0;
for( int i = 4; i <= N; i++ ) {
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + dp[ i - 1 ][ 1 ];
dp[ i ][ 1 ] = dp[ i - 4 ][ 0 ] + dp[ i - 4 ][ 1 ];
}
ans += dp[ N ][ 0 ] + dp[ N ][ 1 ] - 1;
printf("%lld\n", ans );
return 0;
}
Binary file added 117/117
Binary file not shown.
27 changes: 27 additions & 0 deletions 117/117.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <cstdio>

#define N 50

typedef unsigned long long llu;

// 0 -> black
// 1 -> red
// 2 -> green
// 3 -> blue

int main( void )
{
llu dp[ N + 1 ][ 4 ];
dp[ 0 ][ 0 ] = 1;
dp[ 0 ][ 1 ] = 0;
dp[ 0 ][ 2 ] = 0;
dp[ 0 ][ 3 ] = 0;
for( int i = 1; i <= N; i++ ) {
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + dp[ i - 1 ][ 1 ] + dp[ i - 1 ][ 2 ] + dp[ i - 1 ][ 3 ];
dp[ i ][ 1 ] = ( i - 2 >= 0 ? ( dp[ i - 2 ][ 0 ] + dp[ i - 2 ][ 1 ] + dp[ i - 2 ][ 2 ] + dp[ i - 2 ][ 3 ] ) : 0 );
dp[ i ][ 2 ] = ( i - 3 >= 0 ? ( dp[ i - 3 ][ 0 ] + dp[ i - 3 ][ 1 ] + dp[ i - 3 ][ 2 ] + dp[ i - 3 ][ 3 ] ) : 0 );
dp[ i ][ 3 ] = ( i - 4 >= 0 ? ( dp[ i - 4 ][ 0 ] + dp[ i - 4 ][ 1 ] + dp[ i - 4 ][ 2 ] + dp[ i - 4 ][ 3 ] ) : 0 );
}
printf("%llu\n", dp[ N ][ 0 ] + dp[ N ][ 1 ] + dp[ N ][ 2 ] + dp[ N ][ 3 ] );
return 0;
}
Binary file added 150/150
Binary file not shown.
50 changes: 50 additions & 0 deletions 150/150.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <cstdio>
#include <algorithm>
#include <cassert>

#define N 1000
#define PSEUDO 500500
#define MOD ( 1 << 20 )
#define INF 112233445566778899

using namespace std;

long long parsum[ N + 1 ][ N + 1 ], A[ PSEUDO + 1 ], tri[ N + 1 ][ N + 1 ];

int main( void )
{
long long ans = INF, t = 0;
for( int i = 1; i <= PSEUDO; i++ ) {
t = 615949*t % MOD + 797807 % MOD;
A[ i ] = ( t % MOD ) - ( 1 << 19 );
}
t = 1;
for( int i = 1; i <= N; i++ ) {
for( int j = 1; j <= i; j++ ) {
tri[ i ][ j ] = A[ t++ ];
}
}
for( int i = 1; i <= N; i++ ) {
parsum[ i ][ 0 ] = 0;
for( int j = 1; j <= i; j++ ) {
parsum[ i ][ j ] = parsum[ i ][ j - 1 ] + tri[ i ][ j ];
}
}
for( int i = 1; i <= N; i++ ) {
for( int j = 1; j <= i; j++ ) {
long long sum = tri[ i ][ j ], cell = j;
ans = min( ans, sum );
for( int k = i + 1; k <= N; k++ ) {
if( cell + 1 > k ) {
break;
}
int diff = k - i + 1;
sum += parsum[ k ][ cell + 1 ] - parsum[ k ][ cell + 1 - diff ];
cell++;
ans = min( ans, sum );
}
}
}
printf("%lld\n", ans );
return 0;
}
Binary file added 161/161
Binary file not shown.
75 changes: 75 additions & 0 deletions 161/161.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>

#define N 12
#define M 9

#define X first
#define Y second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair< pair< pair< int, int >, pair< int, int > >, int > state;

map<state, ll > memo;

ll dp( int i, int j, int bit1, int bit2, int bit3 )
{
ll& ans = memo[ mp( mp( mp( i, j ), mp( bit1, bit2 ) ), bit3 ) ];
if( ans ) return ans;
if( i == N ) return ans = ( bit1 == 0 && bit2 == 0 && bit3 == 0 );
if( j == M ) return ans = dp( i + 1, 0, bit2, bit3, 0 );
if( bit1 & ( 1 << j ) ) return ans = dp( i, j + 1, bit1, bit2, bit3 );
ans = 0;
ll ret = 0;
for( int n = 0; n <= 5; n++ ) {
if( n == 0 ) {
if( j + 3 <= M && !( bit1 & ( 1 << j ) ) && !( bit1 & ( 1 << ( j + 1 ) ) ) && !( bit1 & ( 1 << ( j + 2 ) ) ) ) {
ret += dp( i, j + 3, bit1, bit2, bit3 );
}
}
else if( n == 1 ) {
if( i + 3 <= N && !( bit1 & ( 1 << j ) ) && !( bit2 & ( 1 << j ) ) && !( bit3 & ( 1 << j ) ) ) {
ret += dp( i, j + 1, bit1, bit2 | ( 1 << j ), bit3 | ( 1 << j ) );
}
}
else if( n == 2 ) {
if( j + 2 <= M && !( bit1 & ( 1 << j ) ) && !( bit1 & ( 1 << ( j + 1 ) ) ) && !( bit2 & ( 1 << j ) ) ) {
ret += dp( i, j + 2, bit1, bit2 | ( 1 << j ), bit3 );
}
}
else if( n == 3 ) {
if( j + 2 <= M && !( bit1 & ( 1 << j ) ) && !( bit2 & ( 1 << j ) ) && !( bit2 & ( 1 << ( j + 1 ) ) ) ) {
int newbit2 = bit2;
newbit2 |= ( 1 << j );
newbit2 |= ( 1 << ( j + 1 ) );
ret += dp( i, j + 1, bit1, newbit2, bit3 );
}
}
else if( n == 4 ) {
if( j > 0 && !( bit1 & ( 1 << j ) ) && !( bit2 & ( 1 << j ) ) && !( bit2 & ( 1 << ( j - 1 ) ) ) ) {
int newbit2 = bit2;
newbit2 |= 1 << j;
newbit2 |= 1 << ( j - 1 );
ret += dp( i, j + 1, bit1, newbit2, bit3 );
}
}
else if( n == 5 ) {
if( j + 2 <= M && !( bit1 & ( 1 << j ) ) && !( bit1 & ( 1 << ( j + 1 ) ) ) && !( bit2 & ( 1 << ( j + 1 ) ) ) ) {
ret += dp( i, j + 2, bit1, bit2 | ( 1 << ( j + 1 ) ), bit3 );
}
}
}
return ans = ret;
}

int main( void )
{
printf("answer for grid %dx%d -> %lld\n", N, M, dp( 0, 0, 0, 0, 0 ) );
return 0;
}
Loading

0 comments on commit b4d4b32

Please sign in to comment.