【Algothrim】动态规划实例 (PC Assemble)
来源:互联网 发布:python 时间戳 整数 编辑:程序博客网 时间:2024/04/29 17:23
Given below are the raw materials qunatities and their respective selling price(if sold as raw).
D --> No of CPUs
E --> No of memory chips
F --> No of boards
d --> Selling price of CPU
e --> Selling price of Memory chips
We are given N Computer configurations like below:
Di, Ei, Fi, SPi, which are the CPU, Chips, Boards and one unit selling price for ith Computer respectively.
Our task is to maximize the final cost.
Constraints:
1. Can use at Max 3 different Configurations
2. We can use 1 configuration multiple times
3. Remaining Inventories can be sold on its selling price
Input:
T --> Number of test cases.
D E F d e --> Inventories
N --> Total Configuration Count
Di Ei Fi SPi
...
Dn En Fn SPn
1<=T<=10
1<= D, E, F <= 100
1<= d, e <=100000
1<=N<=8
Output:
First Line print the Case #testCaseNumber
Second Line Print Maximum Cost per test case in each line.
Sample Input:
1 --> Total Test Case
10 10 10 2 1 --> D E F d e
1 --> PC Configuration Count
1 2 2 3 --> D1 E1 F1 SP1
Sample Output:
Case #1
30
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define MAXN 10
#define MAXD 102
#define MAXE 102
#define MAXF 102
#define rint register int
struct computer {
int D,E,F,SP;
};
struct point {
int value;
char count,config[MAXN];
};
int Ans,N,D,E,F,sd,se;
struct computer C[MAXN];
struct point dp[MAXD][MAXE][MAXF];
int find(struct point p, int x)
{
int i;
for (i=1;i<=p.count;i++)
if (p.config[i]==x) return 1;
return 0;
}
void copy_config(struct point *p, struct point *q)
{
int i;
p->count=q->count;
for (i=1;i<=p->count;i++)
p->config[i]=q->config[i];
}
int main(void)
{
int T,cd,ce,cf,csp;
rint i,j,k,x,t,count,a,b,c,d,v;
setbuf(stdout,NULL);scanf("%d",&T);
for (t=1;t<=T;t++) {
scanf("%d %d %d %d %d\n%d",&D,&E,&F,&sd,&se,&N);
for (i=j=0;i<N;i++) {
scanf("%d %d %d %d",&cd,&ce,&cf,&csp);
if (cd>D || ce>E || cf>F) continue;
C[++j].D=cd;C[j].E=ce;C[j].F=cf;C[j].SP=csp;
}
N=j;Ans=0;
for (i=0;i<=D;i++)
for (j=0;j<=E;j++)
for (k=0;k<=F;k++) {
dp[i][j][k].value=(i*sd+j*se);
dp[i][j][k].count=0;
}
for (x=1;x<=N;x++)
for (i=C[x].D;i<=D;i++)
for (j=C[x].E;j<=E;j++)
for (k=C[x].F;k<=F;k++) {
a=i-C[x].D;b=j-C[x].E;
c=k-C[x].F;d=C[x].SP;
v=dp[a][b][c].value+d;
if (dp[i][j][k].value>v) continue;
if (dp[i][j][k].value<v) {
dp[i][j][k].value=v;
copy_config(&dp[i][j][k],&dp[a][b][c]);
if (!find(dp[a][b][c],x)) {
count=++dp[i][j][k].count;
dp[i][j][k].config[count]=x;
}
continue;
}
if (dp[i][j][k].count>dp[a][b][c].count)
copy_config(&dp[i][j][k],&dp[a][b][c]);
}
for (i=0;i<=D;i++)
for (j=0;j<=E;j++)
for (k=0;k<=F;k++) {
if (dp[i][j][k].count>3) continue;
v=dp[i][j][k].value+((D-i)*sd+(E-j)*se);
if (Ans<v) Ans=v;
}
printf("Case #%d\n%d\n",t,Ans);
}
return 0;
}
- 【Algothrim】动态规划实例 (PC Assemble)
- 【Algothrim】动态规划法实例1
- 【Algothrim】动态规划法实例2
- 【Algothrim】 动态规划实例(Stamps)
- 【Algothrim】 动态规划实例 (Bone Collector)
- 【Algothrim】 动态规划实例 (Piggy-Bank)
- 【Algothrim】 动态规划
- 【Algothrim】动态规划实例三(Domino Tiling )
- 【Algothrim】动态规划实例四(Business investment)
- 【Algothrim】动态规划实例(0、1背包问题)
- 【Algothrim】动态规划实例 (Scores of marbles )
- 【Algothrim】动态规划实例(最长不下降子序列)
- 【Algothrim】动态规划实例(马拦过河卒)
- 【Algothrim】 动态规划实例 (数字三角形问题)
- 【Algothrim】 动态规划实例(最长公共子序列)
- 【Algothrim】 动态规划实例 (金明的预算方案 )
- 【Algothrim】动态规划实例 (Giving Coins for Candies)
- 【Algothrim】动态规划之背包九讲
- 最大子段和
- 谷歌浏览器自动打印并关闭当前页
- 你和高级工程师的差距在哪里?
- shell练习题
- 获取accesstoken
- 【Algothrim】动态规划实例 (PC Assemble)
- 【top】日常工作中最常用的linux指令示例
- Java IO(二):IO流——字符流
- 百度地图后台持续定位<定位SDK-6.13>
- android4.0.3添加 Ethernet框架支持
- JS中常用到的数组工具方法
- 模运算的规则
- HDU/HDOJ 1004 Let the Balloon Rise(颜色统计)
- 通州十三五规划精华版:增几十万就业机会/一批地铁