Fuzhou University April round 01 backpack

Source: Internet
Author: User

Print? <PRE class = cpp name = "code" sizcache = "1" sizset = "2"> <PRE class = cpp name = "code"> // question link http://acm.fzu.edu.cn/contest/problem.php? Cid = 126 & sortid = 4
</PRE> <PRE class = cpp name = "code"> # include <stdio. h>
# Include <string. h>
 
Struct node
{
Int x;
Int y;
} A [110];
 
Int dp [110] [1100];
Int max (int x, int y)
{
If (x> y) return x;
Return y;
}
Int min (int x, int y)
{
If (x <y) return x;
Return y;
}
 
Int main ()
{
Int n, m, I, sum, j, aa, bb, k;
While (scanf ("% d", & n, & m )! = EOF)
{
Sum = 0;
Memset (dp, 0, sizeof (dp ));

For (I = 1; I <= n; I ++)
{
Scanf ("% d", & a [I]. x, & a [I]. y );
Sum = sum + a [I]. x;
}
Scanf ("% d", & aa, & bb );

For (I = 1; I <= n; I ++)
{
// For (k = min (I, m); k> = 1; k --)
For (k = 1; k <= min (I, m); k ++)
For (j = sum; j> = a [I]. x; j --)
{
Dp [k] [j] = max (dp [k-1] [j], dp [k-1] [j-a [I]. x] + a [I]. y );

}
}
/*
Printf ("% d ************* \ n", sum );
For (I = 0; I <= n; I ++)
{
For (j = 0; j <= sum; j ++)
Printf ("(% d, % d) % d", I, j, dp [I] [j]);
Printf ("\ n ");
}
*/
Int max =-1;



For (I = aa; I <= sum; I ++)
{
If (dp [m] [I]> = bb)
{
If (I + dp [m] [I]-aa-bb)> max)
Max = (I + dp [m] [I]-aa-bb );
// Printf ("(% d, % d) % d", m, I, dp [m] [I]);
}
Printf ("\ n ");
}

// If (max =-1)
Printf ("% d \ n", max );
}


Return 0;
}
 
 
/*
3 2
1 10
3 2
3 4
5 3
*/
 
</PRE> <BR>
<PRE class = cpp name = "code"> Problem D buy candy
Accept: 35 Submit: 127
Time Limit: 1000 mSec Memory Limit: 32768 KB
Problem Description
 
Qing Mingjun, Wuyi Jun, and 61 Jun are good friends.
 
They like to go to a candy store to buy candy, which is sold in two flavors: Chocolate and strawberry. Qing Mingjun prefers chocolate-flavored candy. 61 Jun prefers strawberry-flavored candy. 51 Jun is a fool, and he prefers both flavors. The store owner mixed two flavors of candy in a jar, so the quantity of each candy in each jar may be different.
 
On this day, Qing Mingjun, May 1jun, and 61 Jun went to buy candy. Their money can only buy m cans of candy. Qing Mingjun wants a chocolate-flavored candy. 61 Jun wants B strawberry-flavored candy, and 51 Jun wants more candy, the better. May 1jun wants to know how many sweets he can eat at most to meet the requirements of Qing Ming Jun and 61 Jun.
Input
 
The input contains multiple groups of data.
 
For each group of data, the first behavior is two integers n, m (1 <= m <= n <= 100 ), it indicates the total number of candy cans in the candy store and the number of cans they can buy.
 
Next there are n rows, each row has two integers x, y (0 <= x, y <= 10 ), x chocolate-flavored candy and y strawberry-flavored candy are in the I-Can candy.
 
The last row contains two integers, a and B. It indicates that Qing Mingjun wants a chocolate-flavored candy, and 61 Jun wants B strawberry-flavored candy.
Output
 
Each group of test data outputs an integer in one row, which is the maximum number of Sweets that may be consumed by June. If there is no solution that meets the requirements of Qingming June and liujun,-1 is output.
Sample Input
3 2 1 10 3 2 3 4 5 3
Sample Output
4
 
Dp [I] [j] indicates the first I items. When x sugar j is used, the number of y sugar </PRE> <BR>
<BR>
<PRE> </PRE>
<PRE> </PRE>
 
</PRE>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.