Documente Academic
Documente Profesional
Documente Cultură
Algorithm Design
Spring 2016
Problem Set 3
1 DYNAMIC P ROGRAMMING
3. Next time the same subproblem occurs, instead of recomputing its solution, one sim-
ply looks up the previously computed solution
1
Problem 1. Partition Problem:
Decide whether A can be partitioned into the two sets S 1 and S 2 such that:
|S
P1 | |S
P2 |
S 1 [i ] = S 2 [i ] = B
i =1 i =1
Sample Input
1 5 11 1
8 7 6 5 4
Sample Output
NO
YES
Given a set of n objects, with each tree positive integers height, width and profit (h i , w i , p i ).
and two positive integers H and W which shows the height and width of our knapsack .
The goal is to select a subset K of this objects such that the the selected weight obeys the
knapsack bound :
P
hk ≤ H
k∈K
and
P
wk ≤ W
k∈K
P
and such that the selected profit p k is maximized.
k∈K
Sample Input
15 41 66 77
31 52 9 98
10 20 30 40
90
40
2
Sample Output
1 3
Given two numbers N and K, you are to calculate an amount of valid K based numbers,
containing N digits. You may assume that 2 ≤ K ≤ 10; N ≥ 2; N + K ≤ 18.
Input Format
The numbers N and K in decimal notation separated by the line break.
2
10
Output Format
90
3
Input Format
The first line of the input file contains integer N — the number of members of the club. (
2l eN ≤ 100, 000 ). Next N lines contain two numbers each — S i and B i respectively ( 1 ≤
Si , Bi ≤ 109 ).
4
1 1
1 2
2 1
2 2
Output Format
On the first line of the output file print the maximum number of the people that can be
invited to the party. On the second line output N integers — numbers of members to be
invited in arbitrary order. If several solutions exist, output any one.
2
1 4
Good Luck!