Hdu 3480 Division (slope optimization)

Source: Internet
Author: User

DivisionTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 999999/400000 K (Java/Others)Total Submission (s): 2676 Accepted Submission (s): 1056

Problem DescriptionLittle D is really interested in the theorem of sets recently. There's a problem that confused him a long time.
Let T be a set of integers. let the MIN be the minimum integer in T and MAX be the maximum, then the cost of set T if defined as (MAX-MIN) ^ 2. now given an integer set S, we want to find out M subsets S1, S2 ,..., SM of S, such that



And the total cZ records? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> keys + ClNhbXBsZSBJbnB1dAoKPHByZSBjbGFzcz0 =" brush: java; "> 23 21 2 44 24 7 10 1
Sample Output
Case 1: 1Case 2: 18HintThe answer will fit into a 32-bit signed integer. 

Source2010 ACM-ICPC Multi-University Training Contest (5) -- Host by BJTU
A set containing N elements is divided into M subsets, so that the maximum and least squares of each subset are the same.

Idea: you can think of greedy sorting elements from small to large, and quickly get the minimum cost of j elements in the previous I subsets of dp [I] [j, dp equation dp [I] [j] = dp [I-1] [k] + (a [j]-a [k + 1]); but three loops are required, time complexity is unacceptable, so optimization is required. The slope optimization and quadrilateral inequality are acceptable. I am using the slope optimization just learned. Set k1 Code:
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
       
# Include
       # Include
        
          # Include
         
           # Include
          
            # Include
           
             # Define maxn 205 # define MAXN 100005 # define mod 100000000 # define INF 0x3f3f3f # define pi acos (-1.0) # define eps 1e-6typedef long ll; using namespace std; int n, m, ans, cnt, tot, flag; int a [10005], dp [2] [10005]; int q [10005]; int sqr (int x) {return x * x;} int get (int I, int k) {return dp [I] [k] + a [k + 1] * a [k + 1];} void solve () {int I, j, t, dx1, dy1, dx2, dy2, k1, k2, turn = 0; int head, tail; sort (a + 1, a + n + 1); memset (dp, 0x3f, sizeof (dp); dp [0] [0] = 0; for (I = 1; I <= m; I ++) {head = 0; tail =-1; q [+ tail] = I-1; for (j = I; j <= n; j ++) {while (head
            
             




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.