4 条题解
-
1
java :动态规划
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); HashMap<Integer,Boolean> hash = new HashMap<>(); int n = sc.nextInt(), sum = sc.nextInt(); int[] W = new int[n]; for(int i = 0; i < n; i++){ W[i] = sc.nextInt(); } int[] dp = new int[sum+1]; dp[0] = 1; for (int Wi : W){ for (int i = 0; i + Wi <= sum; i++) { dp[i+Wi] = dp[i+Wi]+dp[i]; } } System.out.println(dp[sum]); } }
信息
- ID
- 577
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 52
- 已通过
- 19
- 上传者