DFS水题(HDU2616)
来源:互联网 发布:广数系统英制螺纹编程 编辑:程序博客网 时间:2024/06/07 03:23
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1635 Accepted Submission(s): 1117
Problem Description
There is a mountain near yifenfei’s hometown. On the mountain lived a big monster. As a hero in hometown, yifenfei wants to kill it.
Now we know yifenfei have n spells, and the monster have m HP, when HP <= 0 meaning monster be killed. Yifenfei’s spells have different effect if used in different time. now tell you each spells’s effects , expressed (A ,M). A show the spell can cost A HP to monster in the common time. M show that when the monster’s HP <= M, using this spell can get double effect.
Now we know yifenfei have n spells, and the monster have m HP, when HP <= 0 meaning monster be killed. Yifenfei’s spells have different effect if used in different time. now tell you each spells’s effects , expressed (A ,M). A show the spell can cost A HP to monster in the common time. M show that when the monster’s HP <= M, using this spell can get double effect.
Input
The input contains multiple test cases.
Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
Output
For each test case output one integer that how many spells yifenfei should use at least. If yifenfei can not kill the monster output -1.
Sample Input
3 10010 2045 895 403 10010 2045 905 403 10010 2045 845 40
Sample Output
32-1import java.awt.RenderingHints.Key;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.Queue;import java.util.Scanner;import java.util.Stack;import java.util.TreeSet;public class Main { static int n, m, sum, max = 10000515; static boolean d[]; static int shu[][]; public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { sum=0; max=10000515; n = in.nextInt(); m = in.nextInt(); shu = new int[n][2]; d = new boolean[n]; for (int i = 0; i < n; i++) { shu[i][0] = in.nextInt(); shu[i][1] = in.nextInt(); } dfs(); if (max == 10000515) { System.out.println("-1"); } else { System.out.println(max); } } } public static void dfs() { for (int i = 0; i < n; i++) { if (d[i] == false) { d[i] = true; int s = 0; if (m <= shu[i][1]) { s = shu[i][0] * 2; } else { s = shu[i][0]; } m -= s; sum++; if (m <= 0) { if (sum < max) { max = sum; } } dfs(); m += s; d[i] = false; sum--; } } }}
阅读全文
1 0
- DFS水题(HDU2616)
- hdu2616
- HDU2616 Kill the monster(深搜DFS)
- ACM-DFS之Kill The Monster——hdu2616
- 09-06 HDU_Steps4.3 DFS剪枝 HDU1010 HDU1016 HDU1426 HDU1455 HDU2510 HDU2553 HDU3290 HDU2616
- hdu2616搜索
- HDU2616 Kill the monster
- hdu2616之简单搜索
- - Kill the monster HDU2616
- hdu2616 kill the monster 4.3.8
- UVa10004 Bicoloring (dfs水题)
- HDU 2212 DFS(水题)
- Oil Deposits(dfs水题)
- DFS水题
- ACM水题-迷宫(AC,DFS)
- UVa 280 Vertex ( dfs搜索 水题 )
- Poj 1321 棋盘问题 (DFS水题)
- LightOJ 1012 Guilty Prince(dfs水题)
- MySQL Innodb MTR源码解析
- Android系统中设置TextView的行间距
- HDU 1078 FatMouse and Cheese(记忆化搜索)
- 如何在泛型参数上进行四则运算和初识dynamic类型
- Spring MVC 入门
- DFS水题(HDU2616)
- 【codevs 1081】线段树练习2(单点查询+区间修改)
- 03-kafka配置server.properties
- EasyUi 下拉选择框onchage( )事件
- C++ function templates(1)---《C++ Templates》
- axaj异步查询学习(多级联动、校对信息)
- ubuntu mysql5.7 改变数据目录
- Ajax实现动态刷新(Post)
- Failed to execute goal maven-javadoc-plugin-----在JDK8下maven-javadoc-plugin插件报错的问题