DP (two times) UVA 10163 Storage Keepers

Source: Internet
Author: User

Topic Portal

1 /*2 Test Instructions: (I don't bother to write, copy online) There are n warehouses, m personal care. A warehouse can only be supervised by one person, and one person may supervise multiple warehouses. 3 Each person has a competency value of pi, and if he oversees the K warehouses, then the safe value for each warehouse being guarded is pi/k (rounded down)4 If a warehouse is not supervised, its security value is 0. Security value for all warehouses L = min{security value per warehouse}5 choose some people from m individuals to hire, ask what the maximum security value is for all warehouses, and in the case of the highest security value, ask for the minimum price of employment (competency value). 6 DP (two times): Dp[i][j] Represents the maximum security value for the first I personal Management J Warehouse, then dp[i][j] = max (Dp[i-1][j-k], p[i]/k) (k is the number of warehouses currently selected)7 Select minimum cost under maximum security value, i.e.: p[i]/k >= dp[m][n], Dp2[i][j] indicates the minimum cost for the first I person to manage J warehouses8 This question I thought for a morning, at the same time consider the safety value and the optimal cost, the result is more disorderly, according to test instructions should be safe first! 9  */Ten /************************************************ One * Author:running_time A * Created time:2015-8-16 9:59:59 - * File Name:UVA_10163.cpp -  ************************************************/ the  -#include <cstdio> -#include <algorithm> -#include <iostream> +#include <sstream> -#include <cstring> +#include <cmath> A#include <string> at#include <vector> -#include <queue> -#include <deque> -#include <stack> -#include <list> -#include <map> in#include <Set> -#include <bitset> to#include <cstdlib> +#include <ctime> - using namespacestd; the  * #defineLson L, Mid, RT << 1 $ #defineRson mid + 1, R, RT << 1 | 1Panax NotoginsengtypedefLong Longll; - Const intMAXN = 1e2 +Ten; the Const intMAXM = -; + Const intINF =0x3f3f3f3f; A Const intMOD = 1e9 +7; the intDP[MAXM][MAXN], DP2[MAXM][MAXN]; + intP[MAXM]; -  $ intMainvoid)    {//UVA 10163 Storage Keepers $     intN, M; -      while(SCANF ("%d%d", &n, &m) = =2) { -         if(!n &&!m) Break; the          for(intI=1; i<=m; ++i) scanf ("%d", &p[i]); -Memset (DP,0,sizeof(DP));Wuyi          for(intI=1; i<=m; ++i) { thedp[i-1][0] =INF; -              for(intj=1; j<=n; ++j) { WuDP[I][J] = dp[i-1][j]; -                  for(intk=1; k<=j; ++k) { AboutDP[I][J] = max (Dp[i][j], min (dp[i-1][J-K], P[i]/k)); $                 } -             } -         } -memset (DP2, INF,sizeof(DP2)); A          for(intI=1; i<=m; ++i) { +dp2[i-1][0] =0; the              for(intj=1; j<=n; ++j) { -DP2[I][J] = dp2[i-1][j]; $                  for(intk=1; k<=j; ++k) { the                     ints = p[i]/K; the                     if(S >=Dp[m][n]) { theDp2[i][j] = min (dp2[i][j], dp2[i-1][J-K] +p[i]); the                     } -                 } in             } the         } the  Aboutprintf ("%d%d\n", Dp[m][n], (dp[m][n] = =0) ?0: Dp2[m][n]); the     } the  the     return 0; +}

DP (two times) UVA 10163 Storage Keepers

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.