USACO3.32Shopping Offers(DP)

时间:2022-08-24 14:49:57

五维DP,听着挺多的,貌似就是挺裸的dp,

最近貌似做简单的DP挺顺手。。1A

dp[i][j][e][o][g] = min(dp[i][j][e][o][g],dp[i-i1][j-i2][e-i3][o-i4][g-i5]+p[q])  i1,i2...为满足给出的商品数量的值 p[q]为选用当前优惠方案的价格。

 /*
ID: shangca2
LANG: C++
TASK: shopping
*/
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define INF 0xfffffff
int dp[][][][][];
struct node
{
int c[],k[],p,n;
}pp[];
int c[],k[],p[];
int main()
{
freopen("shopping.in","r",stdin);
freopen("shopping.out","w",stdout);
int i,j,s,b,e,o,g,q,a;
for(i = ; i <= ; i++)
for(j = ; j <= ; j++)
for(e = ; e <= ; e++)
for(o = ; o <= ; o++)
for(g = ; g <= ; g++)
dp[i][j][e][o][g] = INF;
cin>>s;
for(i = ; i <= s ; i++)
{
cin>>pp[i].n;
for(j = ; j <= pp[i].n ; j++)
cin>>pp[i].c[j]>>pp[i].k[j];
cin>>pp[i].p;
}
cin>>b;
for(i = ; i <= b ;i++)
cin>>c[i]>>k[i]>>p[i];
for(i = ;i <= k[] ; i++)
for(j = ; j <= k[] ; j++)
for(e = ; e <= k[] ; e++)
for(o = ; o <= k[] ;o++)
for(g = ; g <= k[] ; g++)
{
dp[i][j][e][o][g] = i*p[]+j*p[]+e*p[]+o*p[]+g*p[];
for(q = ; q <= s ; q++)
{
int i1=,i2=,i3=,i4=,i5=;
for(a = ; a <= pp[q].n ;a++)
{
if(pp[q].c[a]==c[])
i1 = pp[q].k[a];
else if(pp[q].c[a]==c[])
i2 = pp[q].k[a];
else if(pp[q].c[a]==c[])
i3 = pp[q].k[a];
else if(pp[q].c[a]==c[])
i4 = pp[q].k[a];
else
i5 = pp[q].k[a];
}
if(i-i1>=&&j-i2>=&&e-i3>=&&o-i4>=&&g-i5>=)
{
dp[i][j][e][o][g] = min(dp[i][j][e][o][g],dp[i-i1][j-i2][e-i3][o-i4][g-i5]+pp[q].p);
}
}
}
cout<<dp[k[]][k[]][k[]][k[]][k[]]<<endl;
return ;
}