"Noip 2006 to improve" Kim's budget plan |
|
Time limit:10000ms Memory limit:65536k Total submit:485 accepted:222 Case Time Limit:1000ms Description Kim is very happy today, the home purchase of the new house on the key, the new house has a personal dedicated to the very spacious room. More let him happy is, mother yesterday said to him: "Your room needs to buy which items, how to decorate, you decide, as long as no more than n yuan money on the line." This morning, Kim began to do the budget, he wants to buy items into two categories: the main parts and accessories, attachment is subordinate to a certain main parts, the following table is a number of main parts and accessories examples:
If you want to buy an item that is categorized as an attachment, you must first buy the main part that the attachment belongs to. Each main piece can have 0, one, or 2 attachments. Attachment no longer has an attachment from itself. Kim is going to buy a lot of things, will certainly exceed the mother limit of N yuan. So he set an important degree for each item, divided into 5 and so on: With the integer 1~5, 5th, the most important. He also found the price of each item on the Internet (10 yuan multiple). He wants to make the sum of the product of each item's price and importance the largest, if not more than N-ary (can equal n-ary). Set the price of J items for V[j], the importance of w[j], a total of selected K items, numbered sequentially j1,j2,......,jk, then the sum is: v[j1]*w[j1]+v[j2]*w[j2]+ ... +v[jk]*w[jk]. (of which * for multiplication) Please help Kim to design a shopping list to meet the requirements.
Input Enter the 1th line of the file, two positive integers, separated by a single space: Nm where N (<32000) represents the total amount of money, M (<60) is the number of items you want to buy. ) From line 2nd to m+1, Line J gives basic data for items numbered J-1, with 3 non-negative integers per line V P q (where v indicates the price of the item (v<10000), p indicates the importance of the item (1~5), q Indicates whether the item is the main part or the attachment.) If the q=0, indicating the main part of the article, if the q>0, indicating that the item is an attachment, Q is the main part of the number)
Output The output file has only one positive integer, the maximum value (<200000) of the sum of the product of the price of the item that does not exceed the total amount of money.
Sample Input 1000 5
2 0
5 1 5
1/3 0 500 2 0
Sample Output 2200
Source xinyue--noip2006 second question |
Title: http://mail.bashu.cn:8080/bs_oj/showproblem?problem_id=1512
I want to buy m items, and the amount of money can not exceed N, some items have dependencies ...
Analysis: Similar to the selection of the subject, but if this problem is not optimized, it is estimated to be difficult ...
Code:
#include <cstdio>
#include <iostream>
using namespace std;
const int mm=33333;
int f[99][mm],v[99],p[99],q[99];
int i,n,m;
void TREEDP (int k,int c)
{
if (c) for (int i=1,j;i<=n;++i)
if (q[i]==k)
{for
(j=0;j<=c-v[i) ; ++j) f[i][j]=f[k][j]+v[i]*p[i];
TREEDP (I,c-v[i]);
for (J=V[I];J<=C;++J)
F[k][j]=max (F[k][j],f[i][j-v[i]]);
}
int main ()
{
while (~scanf ("%d%d", &m,&n))
{for
(i=1;i<=n;++i)
scanf ("%d%d%d" , &v[i],&p[i],&q[i]);
for (I=0;i<=m;++i) f[0][i]=0;
TREEDP (0,m);
printf ("%d\n", F[0][m]);
return 0;
}