Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import java.util.Collection; import java.util.Arrays; import java.util.Scanner; public class MAin { private static int n; private static int[] niza; private static int[] dp; static int rec(int x) { if(x == 0) { return 0; } if(dp[x] != -1) { return dp[x]; } int result = (int) 2e9; for(int i = 0; i < n; i++) { if(x - niza[i] >= 0) { result = Math.min(result, rec(x - niza[i]) + 1); } } dp[x] = result; return result; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); niza = new int[n]; for(int i = 0; i < n; i++) { niza[i] = sc.nextInt(); } int suma = sc.nextInt(); dp = new int[suma + 1]; for(int i = 0; i <= suma; i++) { dp[i] = -1; // ova ni kazuva deka ovaa rekurzija ne e presmetana } System.out.println(rec(suma)); } } // 50- 10 - 20 = 20 // 60 + 100 +
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)