From 5110dc863be97d9dfcbc6ef8bab6b63d2013d98c Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 24 May 2016 14:03:41 +0800 Subject: [PATCH] Create 1170.cpp --- POJ/1170.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 POJ/1170.cpp diff --git a/POJ/1170.cpp b/POJ/1170.cpp new file mode 100644 index 0000000..82140d6 --- /dev/null +++ b/POJ/1170.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +using namespace std; + +/// ItemID[0]=7 stands for "When C=7, This object id is 0" +int ItemID[6]; +/// Amount of Item with ID. +int ItemAmount[6]; +/// Price of Item with ID. +int ItemPrice[6]; + +#define MAX_INT 1e9 + +/// Bucket +int b; +/// Special Combinations. +int s; + +///Array of DP +int dp[6][6][6][6][6]; + +int special_combine[1000][6]; +int special_price[1000]; + +void Solve() +{ + /// May be dangerous. + memset(dp,-1,sizeof(dp)); + + dp[0][0][0][0][0]=0; + /// i,j,k,x,y respects the amount of selected Item, from 0 to 5 + for(int i=0;i<=ItemAmount[0];i++) + { + for(int j=0;j<=ItemAmount[1];j++) + { + for(int k=0;k<=ItemAmount[2];k++) + { + for(int x=0;x<=ItemAmount[3];x++) + { + for(int y=0;y<=ItemAmount[4];y++) + { + int FinalPrice = MAX_INT; + int TempPrice = MAX_INT; + /// Try Each Special Combination + for(int si=0;si=special_combine[si][0]&&j>=special_combine[si][1]&&k>=special_combine[si][2]&&x>=special_combine[si][3]&&y>=special_combine[si][4]) + { + TempPrice = dp[i-special_combine[si][0]][j-special_combine[si][1]][k-special_combine[si][2]][x-special_combine[si][3]][y-special_combine[si][4]] +special_price[si]; + FinalPrice = min(FinalPrice,TempPrice); + } + } + if(FinalPrice!=MAX_INT) + { + dp[i][j][k][x][y]=FinalPrice; + } + else + { + /// Just Calculate the original price + dp[i][j][k][x][y]=i*ItemPrice[0]+j*ItemPrice[1]+k*ItemPrice[2]+x*ItemPrice[3]+y*ItemPrice[4]; + } + } + } + } + } + } +} + +int main() +{ + scanf("%d",&b); + for(int i=0;i