Bailian 4118: Open a restaurant

Source: Internet
Author: User
Tags ming

Bailian 4118: Open a restaurant
  • View
  • Submit
  • Statistics
  • Tips
  • Questions
Total time limit:1000ms Memory Limit:65536kBDescriptionXiao Ming, a student of PKU School of Information, intends to open a restaurant after graduation. There are now N locations to choose from. Xiao Ming intends to choose the right location to open some restaurants. The n locations are arranged in a straight line. We use an integer sequence m1, M2, ... mn to represent their relative position. Because of the lot relationship, the profit of the restaurant will be different. We use PI to show the profit of opening a restaurant in Mi. In order to avoid the internal competition of their own restaurants, the distance between restaurants must be greater than K. Please help Xiao Ming to choose a plan with the biggest total profit.  inputThe standard input contains several sets of test data. The input first line is the integer t (1 <= T <= 1000), indicating that there is a T group of test data. followed by a continuous test of the T-group. Each set of test data has 3 rows,Line 1th: Total number of places N (n < 100), distance limit K (k > 0 && K < +).Line 2nd: N Locations M1, M2, ... mn (1000000 > Mi > 0 and Integer, ascending)Line 3rd: Restaurant profit in n locations p1, p2, ... pn (> Pi > 0 and integer)Outputmaximum possible profit for each set of test dataSample Input2 3 1 2 (2 , 3, 1 2) 2Sample Output All Save the position with array A, array B holds the profit for each position, and the array C represents the total profit.  
#include <cstdio>#include<cstring>#include<iostream>#include<queue>#include<stack>#include<cmath>#include<map>#include<algorithm>using namespaceStd;map<string,string>Mp;vector<vector<int> >G;Const intinf=0x3f3f3f3f;Const intmaxn=1100;intA[MAXN], B[MAXN], C[MAXN];intN, M;intMain () {intT; scanf ("%d", &T);  while(t--) {scanf ("%d%d", &n, &m);  for(intI=1; i<=n; i++) scanf ("%d", &A[i]);  for(intI=1; i<=n; i++) {scanf ("%d", &B[i]); C[i]=B[i]; }          for(intI=1; i<=n; i++)        {             for(intj=1; j<=i-1; J + +)                if(a[i]-a[j]>m) C[i]=max (C[i], c[j]+B[i]); }         intans=0;  for(intI=1; i<=n; i++) ans=Max (ans, c[i]); printf ("%d\n", ans); }    return 0;}

 

Bailian 4118: Open a restaurant

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.