Poj OpenJudge 百练 1062 昂贵的聘礼

时间:2022-09-04 15:26:26

1.Link:

http://poj.org/problem?id=1062

http://bailian.openjudge.cn/practice/1062/

2.Content:

昂贵的聘礼
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 37631   Accepted: 10872

Description

年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。"探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,他可以降低价格。探险家于是又跑到其他地方,其他人也提出了类似的要求,或者直接用金币换,或者找到其他东西就可以降低价格。不过探险家没必要用多样东西去换一样东西,因为不会得到更低的价格。探险家现在很需要你的帮忙,让他用最少的金币娶到自己的心上人。另外他要告诉你的是,在这个部落里,等级观念十分森严。地位差距超过一定限制的两个人之间不会进行任何形式的直接接触,包括交易。他是一个外来人,所以可以不受这些限制。但是如果他和某个地位较低的人进行了交易,地位较高的的人不会再和他交易,他们认为这样等于是间接接触,反过来也一样。因此你需要在考虑所有的情况以后给他提供一个最好的方案。 
为了方便起见,我们把所有的物品从1开始进行编号,酋长的允诺也看作一个物品,并且编号总是1。每个物品都有对应的价格P,主人的地位等级L,以及一系列的替代品Ti和该替代品所对应的"优惠"Vi。如果两人地位等级差距超过了M,就不能"间接交易"。你必须根据这些数据来计算出探险家最少需要多少金币才能娶到酋长的女儿。 

Input

输入第一行是两个整数M,N(1 <= N <= 100),依次表示地位等级差距限制和物品的总数。接下来按照编号从小到大依次给出了N个物品的描述。每个物品的描述开头是三个非负整数P、L、X(X < N),依次表示该物品的价格、主人的地位等级和替代品总数。接下来X行每行包括两个整数T和V,分别表示替代品的编号和"优惠价格"。

Output

输出最少需要的金币数。

Sample Input

1 4
10000 3 2
2 8000
3 5000
1000 2 1
4 200
3000 2 1
4 200
50 2 0

Sample Output

5250

Source

3.Method:

dijkstra算法的应用,这题还增加了等级的考虑,我使用的枚举,然后运用算法前直接排除掉等级不符合要求的

4.Code:

 #include <iostream>
 #include <cstring>
 #include <limits>
 #include <cstdlib>
 #include <cmath>

 using namespace std;

 int intMax = numeric_limits<int>::max();

 int main()
 {
     //freopen("D://input.txt","r",stdin);
     int i,j, k, ii;

     int m, n;
     cin >> m >> n;
     //cout << m << " " << n << endl;

     int **arr_map = new int*[n];
     ; i < n; ++i)
     {
         arr_map[i] = new int[n];
         ; j < n; ++j) arr_map[i][j] = intMax;
     }

     int *arr_p = new int[n];
     int *arr_L = new int[n];

     int p,L,x;
     ; i < n; ++i)
     {
         cin >> p >> L >> x;
         arr_p[i] = p;
         arr_L[i] = L;

         int t,v;
         ; j < x; ++j)
         {
             cin >> t >> v;
             arr_map[t - ][i] = v;
         }
     }

     //for(j = 0; j < n; ++j)
     //{
     //    for(k = 0; k < n; ++k) cout << arr_map[j][k] << " ";
     //    cout << endl;
     //}
     //cout << endl;

     ];

     int *arr_d = new int[n];
     bool *arr_m = new bool[n];

     int **arr_map2 = new int*[n];
     ; i < n; ++i) arr_map2[i] = new int[n];

     ; i < n; ++i)
     {
         ; ii <= m; ++ii)
         {
             int l_bettom = arr_L[i] - m + ii;
             int l_top = arr_L[i] + ii;

             ; j < n; ++j) memcpy(arr_map2[j], arr_map[j], sizeof(int) * n);
             ; j < n; ++j)
             {
                 /*if(abs(arr_L[j] - arr_L[i]) > m)
                 {
                     for(k = 0; k < n; ++k)
                     {
                         arr_map2[k][j] = intMax;
                         arr_map2[j][k] = intMax;
                     }
                 }*/
                 if(arr_L[j] < l_bettom || arr_L[j] > l_top)
                 {
                     ; k < n; ++k)
                     {
                         arr_map2[k][j] = intMax;
                         arr_map2[j][k] = intMax;
                     }
                 }
             }

             //for(j = 0; j < n; ++j)
             //{
             //    for(k = 0; k < n; ++k) cout << arr_map2[j][k] << " ";
             //    cout << endl;
             //}
             //cout << endl;

             memcpy(arr_d, arr_map2[i], sizeof(int) * n);
             memset(arr_m,  ,sizeof(bool) * n);

             arr_d[i] = ;
             arr_m[i] = true;

             ; j < n; ++j)
             {
                 int min_d = intMax;
                 int idx_d;

                 ; k < n; ++k)
                 {
                     if(!arr_m[k] && min_d > arr_d[k])
                     {
                         min_d = arr_d[k];
                         idx_d = k;
                     }
                 }
                 if(min_d == intMax) break;

                 arr_m[idx_d] = true;
                 ; k < n; ++k)
                 {
                     if(!arr_m[k] && arr_map2[idx_d][k] != intMax && min_d + arr_map2[idx_d][k] < arr_d[k])
                     {
                         arr_d[k] = min_d + arr_map2[idx_d][k];
                     }
                 }

                 //for(k = 0; k < n; ++k) cout << arr_d[k] << " ";
                 //cout << endl;
             }

             ] != intMax && min_p > arr_d[] + arr_p[i]) min_p = arr_d[] + arr_p[i];
         }
     }

     cout << min_p << endl;

     ; i < n; ++i) delete [] arr_map2[i];
     delete [] arr_map2;

     delete [] arr_m;
     delete [] arr_d;

     delete [] arr_L;
     delete [] arr_p;

     ; i < n; ++i) delete [] arr_map[i];
     delete [] arr_map;

     ;
 }

5.Reference:

Poj OpenJudge 百练 1062 昂贵的聘礼的更多相关文章

  1. Poj OpenJudge 百练 1860 Currency Exchang

    1.Link: http://poj.org/problem?id=1860 http://bailian.openjudge.cn/practice/1860 2.Content: Currency ...

  2. Poj OpenJudge 百练 2602 Superlong sums

    1.Link: http://poj.org/problem?id=2602 http://bailian.openjudge.cn/practice/2602/ 2.Content: Superlo ...

  3. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  4. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  5. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  6. Poj OpenJudge 百练 Bailian 1008 Maya Calendar

    1.Link: http://poj.org/problem?id=1008 http://bailian.openjudge.cn/practice/1008/ 2.content: Maya Ca ...

  7. poj 1062 昂贵的聘礼 (dijkstra最短路)

    题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  8. 最短路&lpar;Dijkstra&rpar; POJ 1062 昂贵的聘礼

    题目传送门 /* 最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路 更新每个点的最短路的最小值 注意:国王的等级不一定是最高的:) */ #i ...

  9. POJ 1062 昂贵的聘礼(图论,最短路径)

    POJ 1062 昂贵的聘礼(图论,最短路径) Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女 ...

随机推荐

  1. ubuntu kylin 14&period;04安装配置redis-2&period;8&period;9&lpar;转&rpar;

    1.下载安装文件加压.编译和安装 cd /tmpwget http://download.redis.io/releases/redis-2.8.9.tar.gztar -zxf redis-2.8. ...

  2. 2015暑假多校联合---Assignment(优先队列)

    原题链接 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbere ...

  3. 边工作边刷题:70天一遍leetcode&colon; day 88-5

    coins in a line I/II/III: check above 1. recursion的返回和dp[left][right]表示什么?假设game是[left,right],那么play ...

  4. 人工免疫算法-python实现

    AIAIndividual.py import numpy as np import ObjFunction class AIAIndividual: ''' individual of artifi ...

  5. GIT本地操作

    01. GIT简介(PPT) ================================================================================ 02. ...

  6. 获取spring bean的utils

    <span style="font-size:10px;">package com.record.util; import org.springframework.be ...

  7. ionic2 跳转子页面隐藏底部导航栏

    第一种方法: 在tab里面添加一个属性[tabsHideOnSubPages]='true' <ion-tab [root]="tab1Root" [tabsHideOnSu ...

  8. C&num;实现七牛云存储

    云存储,就是把本地的资源文件存放至网络上,可以公网访问.相当于网盘功能,感觉非常方便. 这里介绍的是七牛云存储.有兴趣的可以去官方网站详看 根据官网的介绍,本身是提供SDK的,下载地址,大家可以根据自 ...

  9. (二 -5) 天猫精灵接入Home Assistant-自动发现Mqtt设备--电风扇

    官网:https://www.home-assistant.io/components/fan.mqtt/ 1 添加配置文件 要在安装中启用MQTT风扇,请将以下内容添加到您的configuratio ...

  10. 记一次免费让网站启用HTTPS的过程

    写在前面 个人网站运行将近2个月了,期间根据酷壳的一篇教程如何免费的让网站启用HTTPS做了一次,中间遇到问题就放下了.昨天孙三苗问我网站地址说要添加友链,出于好奇想看他网站长什么样,顺道也加一下友链 ...