Uva--10604(动规,记忆化搜索)

2014-08-25 00:31:59

CHEMICAL REACTION 

In a chemist’s lab, there are several types of chemicals in tubes. The chemist wants to mix all these chemicals together, two chemicals at a time. Whenever two chemicals are mixed, some heat is generated and released into the air and the mixed chemical is a known chemical of possibly other type than the original two. The resulting chemical type and the amount of heats emitted can looked up in the chemical mixture table.

 

Chemicals

1

2

3

Resulting chemical type

Heats emmited

Resulting chemical type

Heats emmited

Resulting chemical type

Heats emmited

1

1

0

3

-10

3

3000

2

3

-10

2

0

1

-500

3

3

3000

1

-500

3

0

 

For example, in the above chemical mixture table, there are three types of chemicals: 1, 2, and 3. If you mix chemicals 1 and 3, they produce +3000 units of heat and turn into chemical 3. Sometimes, the heat generated can be negative. For instance, you can mix 2 and 3 and they turn into chemical 1 and in the meantime, cool down the lab by 500 units of heat. Since the chemist lacks funding to buy necessary equipments to protect himself from the heat generated, it is utmost important to find a way to mix all the chemicals together that produces the least total heat, regardless of the final chemical type. For example, suppose the lab has four tubes containing chemicals of types 1, 2, 2, and 3. If the chemicals are mixed in the parenthesize order of ((1 2) (2 3)), it will produce (–10)+ (-500)+(3000) = 2490 units of heat. However, if the chemicals are mixed in the (2 (1 (2 3))) order, it will produce (-500)+0+(-10)= -510 units of heat, which is also the least total heat possible.

Input

The first line of input file consists of a single number denoting the number of test cases in the file. There is a single line containing a ‘/’ character separating two consecutive test cases. The end of the file is marked with a line containing a ‘.’ For each test case, the first line contains an integer number m (1≤m≤6) denoting the number chemical types. Therefore, the chemicals are indexed from 1 up to at most 6. The next mxm lines give the chemical mixture table entries in the row-major order. Each line contains the new resulting chemical type and the amount of energy emitted. After the table entries is a line with a single number k (2≤k≤10) denoting number of tubes in the lab. The next line then contains k integers in the range of 1 and m, separated by blank spaces, denoting the types of chemicals in those k tubes.

Output

For each test case, output the least total heat possible on a single line.

 

Sample Input

Sample Output

2

3

1 0

3 -10

3 3000

3 -10

2 0

1 -500

3 3000

1 -500

3 0

4

1 2 2 3

/

3

1 0

3 500

3 -250

3 500

2 0

1 100

3 -250

1 100

3 0

6

1 1 1 2 2 3

.

-510

-650

 

思路:这题。。。个人认为写了个效率非常不高的算法,因为最多只有6中化学品,直接开6维dp数组记忆化搜索 QAQ。

dp[k1][k2][k3][k4][k5][k6]表示第 i 种化学品还剩 ki 这种状态下所能达到的最小热值,这里需要注意的一点是两种一样的化学品也是可以反应的!!!!(so amazing!)而且更神奇的是2份一样的反应完就剩1份 QAQ,也是醉了。(用vis数组来标记dp是否被计算过比较保险。因为把dp的特殊值(取不到的值)不太好找)

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cmath>
 5 using namespace std;
 6 const int INF = 1 << 30;
 7 
 8 int Case;
 9 int m,k;
10 int gt[7][7];
11 int ge[7][7];
12 int vis[11][11][11][11][11][11];
13 int dp[11][11][11][11][11][11];
14 int ch[11];
15 
16 int Dfs(int a,int b,int c,int d,int e,int f){
17     int &flag = vis[a][b][c][d][e][f];
18     int &tmin = dp[a][b][c][d][e][f];
19     if(flag)
20         return tmin;
21     tmin = INF;
22     flag = 1;
23     for(int i = 1; i <= 6; ++i){
24         for(int j = 1; j <= 6; ++j){
25             if(i == j && ch[i] < 2 || !ch[i] || !ch[j]){
26                 continue;
27             }
28             int tem = gt[i][j];
29             ch[i]--;
30             ch[j]--;
31             ch[tem]++;
32             tmin = min(Dfs(ch[1],ch[2],ch[3],ch[4],ch[5],ch[6]) + ge[i][j],tmin);
33             ch[i]++;
34             ch[j]++;
35             ch[tem]--;
36         }
37     }
38     if(tmin == INF)
39         return tmin = 0;
40     return tmin;
41 }
42 
43 int main(){
44     //freopen("in.txt","r",stdin);
45     scanf("%d",&Case);
46     while(Case--){
47         memset(vis,0,sizeof(vis));
48         memset(ch,0,sizeof(ch));
49         scanf("%d",&m);
50         for(int i = 1; i <= m; ++i){
51             for(int j = 1; j <= m; ++j){
52                 scanf("%d%d",&gt[i][j],&ge[i][j]);
53             }
54         }
55         scanf("%d",&k);
56         int tem;
57         for(int i = 1; i <= k; ++i){
58             scanf("%d",&tem);
59             ch[tem]++;
60         }
61         printf("%d\n",Dfs(ch[1],ch[2],ch[3],ch[4],ch[5],ch[6]));
62         scanf("%*s");
63     }
64     return 0;
65 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/3933963.html

先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完全由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未全面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙与单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了全面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值