File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ const input = require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( ) ;
5+
6+ const parts = input . split ( '-' ) ;
7+
8+ let result = parts [ 0 ] . split ( '+' ) . reduce ( ( acc , num ) => acc + parseInt ( num ) , 0 ) ;
9+
10+ for ( let i = 1 ; i < parts . length ; i ++ ) {
11+ const sum = parts [ i ] . split ( '+' ) . reduce ( ( acc , num ) => acc + parseInt ( num ) , 0 ) ;
12+ result -= sum ;
13+ }
14+
15+ console . log ( result ) ;
Original file line number Diff line number Diff line change 1+ const input = require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( )
5+ . split ( ' ' )
6+ . map ( Number ) ;
7+
8+ const [ N , K ] = input ;
9+
10+ const dp = Array . from ( { length : K + 1 } , ( ) => Array ( N + 1 ) . fill ( 0 ) ) ;
11+
12+ for ( let i = 0 ; i <= K ; i ++ ) {
13+ dp [ i ] [ 0 ] = 1 ;
14+ }
15+
16+ for ( let i = 1 ; i <= K ; i ++ ) {
17+ for ( let j = 1 ; j <= N ; j ++ ) {
18+ dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j ] ) % 1000000000 ;
19+ }
20+ }
21+
22+ console . log ( dp [ K ] [ N ] ) ;
You can’t perform that action at this time.
0 commit comments