(中等) 动态规划 HOJ 2177 ICPC Strikes Again
来源:互联网 发布:碧柔防晒知乎 编辑:程序博客网 时间:2024/06/05 19:08
ICPC Strikes Again
Submitted : 85, Accepted : 36
International Concrete Projects Company (ICPC) is a construction company which specializes in building houses for the high-end market. The company is the most profitable company in the world due to a very efficient land division method which has been used in its housing development projects since last year. Recently there was a chaos at ICPC, because employees refused to work arguing that they did not earn enough. Worried about the loss in profit due to the strike, the company board proposed a new method to calculate the salaries which was luckily accepted by everyone.
The salary of a worker reflects the significance of the tasks that he/she has to perform and is influenced by the way tasks depend on each other.
A task X depends on a task Y if either (i) X depends directly on Y , or (ii) there exists a task T such that X depends directly on T and T depends on Y . Since in ICPC all tasks must be performed, there is no circularity in the task dependence relation. Also, a task may be performed by more than one worker.
A basic significance is associated with each task reflecting its importance (for example, developing the efficient land division method is more important than building the houses themselves). The significance of a task T is then defined as the basic significance of T plus the significance of every task which depends directly on T. Note that if no other tasks depend directly on task T, the basic significance and the significance of T are the same. The salary of a worker is the sum of the significances of all the tasks he/she performs which do not depend on any other task performed by him/her. In other words, a value equal to the significance of task X will be added to the salary of a worker W that works in task X if there is no other task Y on which X depends, and W works also in Y .
ICPC wants you to help them to determine the salary of each of its employees.
Input
The input contains several test cases.
The first line of a test case contains two integers T and E indicating respectively the number of tasks and the number of employees (1 <= T <= 1000 and 1 <= E <= 1000). Tasks are numbered from 1 to T and employees from 1 to E.
Then it will come a sequence of lines describing the tasks 1 to T in ascending order. Each task is described by two lines. The first of these lines contains three integers BS, ND and NE, representing respectively the basic significance of the task, the number of tasks that depend directly on it, and the number of employees who perform it (1 <= BS <= 1000, 0 <= ND < T and 1 <= NE <= E). The second line contains ND+NE integers corresponding first to the ND directly dependent tasks and then the NE employees who perform the task.
The end of input is indicated by T = E = 0.
Output
Test cases must be answered in the order that they were presented. For each test case you must print:
- a single line containing five stars ***** indicating the beginning of the case
- for each employee i, one line with two integers i and s, separated by a blank, meaning that i has a salary of s.
Sample Input
3 2100 2 22 3 1 240 0 1160 0 127 210 2 12 3 110 2 14 5 210 2 16 7 210 0 1110 0 1110 0 1110 0 110 0
Sample Output
*****1 2002 200*****1 702 60
- (中等) 动态规划 HOJ 2177 ICPC Strikes Again
- (中等)动态规划Hoj 1719 Spiderman
- (中等) 动态规划+搜索 HOJ 2156 Colored stones
- *(中等)动态规划 HOJ 2508 Pitcher Rotation
- (中等)动态规划 HOJ 1770 Old Wine Into New Bottles
- HOJ-1005 Fast Food(动态规划)
- HOJ-2056 Bookshelf(线性动态规划)
- HOJ 2252 The Priest(动态规划)
- 动态规划-HOJ-2571
- HOJ 2133&POJ 2964 Tourist(动态规划)
- HOJ 2139 Spiderman's workout(动态规划)
- nyoj104最大和--中等难度--动态规划
- 哈工大hoj第1042题,动态规划
- 动态规划-免费的馅饼-HOJ-1176
- URAL 1221 Malevich Strikes Back! (DP动态规划 O(n^2) )
- (中等) 搜索 HOJ 1049 sticks
- *(中等) dp HOJ 2133 Tourist
- [中等] 动态规划经典-堆石子问题
- (中等) 状态压缩dp HOJ 1894 Islands and Bridges
- (简单) dp HOJ 2091 Chess
- (简单) 博弈 HOJ 2128 S-Nim
- (中等) 最短路 HOJ 2132 Easter holidays
- Android之菜单一——选项菜单
- (中等) 动态规划 HOJ 2177 ICPC Strikes Again
- (中等) 树形dp HOJ 2178 Optical Fiber
- (简单) 不需要算法 HOJ 1019 Grandpa\'s Other Estate
- *数论 HOJ 3110 Remoteland
- 博弈论 HOJ 1122 Number Game
- 字符串(最小表示法) HOJ 1223 Hidden Password
- 搜索 HOJ 1266 Phone Home
- 搜索 HOJ 1281 Lagrange\'s Four-Square Theorem
- *搜索 HOJ 1320 Square Destroyer
程序博客网,程序员的互联网技术博客家园。csdn论坛精品 msdn技术资料都在这里