锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
]]>
dp[i][j][k][m][n] = min ( dp[i][j][k][m][n], dp[i-o[0]][j-o[1]][k-o[2]][m-o[3]][n-o[4]]+offer.cost);
analysis涓彁鍑虹敤鏈鐭礬寰勭殑鏂規(guī)硶鏉ヨВ錛屾濊礬寰堝閥濡欍傛妸鈥濊鏈変笉鍚岀鏁板拰鏁伴噺鐨勭墿鍝佲滅殑綃瓙鐪嬩綔緇撶偣錛屾妸offer浣滀負(fù)杈?鎶婅喘涔頒竴浠剁墿鍝佺殑鍘熷浠鋒牸鐪嬫垚涓縐嶉鍖栫殑offer)錛屾妸浠鋒牸浣滀負(fù)杈歸暱搴︺傝繖鏍峰氨杞崲鎴愪粠綃瓙(0,0,0,0,0)鍒版墍姹傜粨鐐圭殑鏈鐭礬寰勯棶棰樸?br />
浠g爜濡備笅:
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("shopping.in");
ofstream聽fout("shopping.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽dp[6][6][6][6][6];
struct聽offer{
聽聽聽聽int聽pro_num;
聽聽聽聽int聽price;
聽聽聽聽int聽product[5];
聽聽聽聽int聽amount[5];
};
int聽offer_num;
offer聽offers[100];
int聽map[1000]; //product id鍒扳濇寜鐗╁搧鍑虹幇欏哄簭鎵緇欑殑緙栧彿鈥滅殑鏄犲皠
int聽price[1000];//product id瀵瑰簲鐨勭墿鍝佷環(huán)鏍?br />int聽product_num;//鐗╁搧鎬繪暟鐩?br />int聽products[5];//瀛樻斁product id
int聽amount[5];//product 鎵闇鐨勬暟閲?br />
void聽solve()
{
聽聽聽聽in>>offer_num;
聽聽聽聽for(int聽i=0;i<offer_num;++i){
聽聽聽聽聽聽聽聽in>>offers[i].pro_num;
聽聽聽聽聽聽聽聽for(int聽j=0;j<offers[i].pro_num;++j){
聽聽聽聽聽聽聽聽聽聽聽聽in>>offers[i].product[j]>>offers[i].amount[j];
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽in>>offers[i].price;
聽聽聽聽}
聽聽聽聽
聽聽聽聽int聽pro_idx聽=聽0;
聽聽聽聽in>>product_num;
聽聽聽聽for(int聽i=0;i<product_num;++i){
聽聽聽聽聽聽聽聽in>>products[i];
聽聽聽聽聽聽聽聽in>>amount[i];
聽聽聽聽聽聽聽聽in>>price[i];
聽聽聽聽聽聽聽聽map[聽products[i]聽]聽=聽i;
聽聽聽聽}
聽聽聽 //娌℃湁鎶樻墸鏃剁殑浠鋒牸
聽聽聽聽for(int聽i=0;i<=5;++i)
聽聽聽聽聽聽聽聽for(int聽j=0;j<=5;++j)
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽k=0;k<=5;++k)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽m=0;m<=5;++m)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽n=0;n<=5;++n){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i][j][k][m][n]聽=聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[0]*i+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[1]*j+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[2]*k+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[3]*m+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[4]*n;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽for(int聽i=0;i<=5;++i)
聽聽聽聽聽聽聽聽for(int聽j=0;j<=5;++j)
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽k=0;k<=5;++k)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽m=0;m<=5;++m)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽n=0;n<=5;++n){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽int聽tmp[5];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽s=0;s<offer_num;++s){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽memset(tmp,0,sizeof(tmp));聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽t=0;t<offers[s].pro_num;++t){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽tmp[map[offers[s].product[t]]]聽=聽offers[s].amount[t];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i>=tmp[0]&&j>=tmp[1]&&k>=tmp[2]&&m>=tmp[3]&&n>=tmp[4]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i][j][k][m][n]聽=聽min(聽dp[i][j][k][m][n],
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i-tmp[0]][j-tmp[1]][k-tmp[2]][m-tmp[3]][n-tmp[4]]+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽offers[s].price);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽out<<dp[amount[0]][amount[1]][amount[2]][amount[3]][amount[4]]<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
涓婇潰浠g爜鏈変釜涓ラ噸鐨刡ug錛岃阿璋㈢綉鍙嬧滄垜涔熷噾鐑椆"鎸囧嚭銆傜敱浜巑ap鎵鏈夊奸兘涓?銆傛墍浠ユ湭鍦ㄥ晢鍝佸垪琛ㄤ腑鍑虹幇鐨勫晢鍝佺殑map鍊奸兘涓?錛屽嵆閮芥槧灝勪負(fù)絎竴涓晢鍝併傜幇鏀規(guī)垚灝唌ap鍒濆鍖栦負(fù)-1錛屽茍澧炲姞鍒ゆ柇璇彞銆傛澶栧皢鍒濆鍖杁p鐨勮鍙ュ悎騫跺埌鍚庨潰錛屼互綆鍖栦唬鐮併?br />
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("shopping.in");
ofstream聽fout("shopping.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽dp[6][6][6][6][6];
struct聽offer{
聽聽聽聽int聽pro_num;
聽聽聽聽int聽price;
聽聽聽聽int聽product[5];
聽聽聽聽int聽amount[5];
};
int聽offer_num;
offer聽offers[100];
int聽map[1000];
int聽price[1000];
int聽product_num;
int聽products[5];
int聽amount[5];
void聽solve()
{
聽聽聽聽in>>offer_num;
聽聽聽聽for(int聽i=0;i<offer_num;++i){
聽聽聽聽聽聽聽聽in>>offers[i].pro_num;
聽聽聽聽聽聽聽聽for(int聽j=0;j<offers[i].pro_num;++j){
聽聽聽聽聽聽聽聽聽聽聽聽in>>offers[i].product[j]>>offers[i].amount[j];
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽in>>offers[i].price;
聽聽聽聽}
聽聽聽聽
聽聽聽聽int聽pro_idx聽=聽0;
聽聽聽聽in>>product_num;
聽聽聽聽//2009.07.27淇敼
聽聽聽聽memset(map,-1,sizeof(map));
聽聽聽聽for(int聽i=0;i<product_num;++i){
聽聽聽聽聽聽聽聽in>>products[i];
聽聽聽聽聽聽聽聽in>>amount[i];
聽聽聽聽聽聽聽聽in>>price[i];
聽聽聽聽聽聽聽聽map[聽products[i]聽]聽=聽i;
聽聽聽聽}
聽聽聽聽for(int聽i=0;i<=5;++i)
聽聽聽聽聽聽聽聽for(int聽j=0;j<=5;++j)
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽k=0;k<=5;++k)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽m=0;m<=5;++m)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽n=0;n<=5;++n){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i][j][k][m][n]聽=聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[0]*i+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[1]*j+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[2]*k+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[3]*m+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽price[4]*n;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽int聽tmp[5];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽s=0;s<offer_num;++s){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽memset(tmp,0,sizeof(tmp));聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽for(int聽t=0;t<offers[s].pro_num;++t){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//2009.07.27淇敼
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(聽map[offers[s].product[t]]!=-1)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽tmp[map[offers[s].product[t]]]聽=聽offers[s].amount[t];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i>=tmp[0]&&j>=tmp[1]&&k>=tmp[2]&&m>=tmp[3]&&n>=tmp[4]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i][j][k][m][n]聽=聽min(聽dp[i][j][k][m][n],
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i-tmp[0]][j-tmp[1]][k-tmp[2]][m-tmp[3]][n-tmp[4]]+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽offers[s].price);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽out<<dp[amount[0]][amount[1]][amount[2]][amount[3]][amount[4]]<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
]]>
]]>
]]>
]]>
棣栧厛鐢?floyd璁$畻鍑轟袱涓や箣闂寸殑鏈鐭礬寰勩傜劧鍚庣敤dfs灝嗗浘鐫鑹層傚姣忎袱涓や笉鍚岄鑹茬殑緇撶偣錛屾垜浠妸瀹冧滑鐩歌繛錛岀劧鍚庣湅浜х敓鐨勫浘鐨勭洿寰勭殑澶у皬銆?br />鐩村緞鐨勫ぇ灝忓彧鍙兘浠嶄負(fù)鍘熶袱榪為氬浘鐩村緞涔嬩竴錛屾垨鑰呮槸鍖呮嫭鏂版坊鍔犵殑璺緞鎵浜х敓鐨勬渶闀胯礬寰勶紝鍙栬繖涓夎呬腑鐨勬渶澶у箋傛柊璺緞浜х敓鐨勬渶闀胯礬寰勫彧鍙兘鏄袱鐐圭殑璺濈鍔犱笂涓ょ偣鍒板叾浠栫偣鐨勬渶闀胯窛紱匯傛渶寮濮嬬殑鏃跺欏彧鑰冭檻浜嗘柊娣誨姞鐨勮礬寰勶紝娌¤冭檻鍘熺洿寰勪細(xì)姣旀柊璺緞澶х殑鎯呭喌錛寃a浜唍嬈°傘?br />
#include聽<fstream>
#include聽<cfloat>
#include聽<cmath>
using聽namespace聽std;
ifstream聽fin("cowtour.in");
ofstream聽fout("cowtour.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
double聽path[150][150];
char聽graph[150][150];
int聽x[150];
int聽y[150];
int聽n;
int聽color[150];
double聽diameter[150];
double聽maxPath[150];
void聽floyd()
{
聽聽聽聽for(int聽k=0;k<n;++k)
聽聽聽聽聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i!=j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
}
void聽make_color(int聽i,int聽c)
{
聽聽聽聽if(聽color[i]!=0聽)
聽聽聽聽聽聽聽聽return;
聽聽聽聽color[i]聽=聽c;
聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽if(color[j]==0&&graph[i][j])
聽聽聽聽聽聽聽聽聽聽聽聽make_color(j,c);
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽in>>n;
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽in>>x[i]>>y[i];
聽聽聽聽}
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽string聽s;
聽聽聽聽聽聽聽聽in>>s;
聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽graph[i][j]=s[j]-'0';
聽聽聽聽聽聽聽聽聽聽聽聽if(graph[i][j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]聽=聽sqrt(聽(x[i]-x[j])*(x[i]-x[j])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽+(y[i]-y[j])*(y[i]-y[j])聽);
聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]聽=聽DBL_MAX/4;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽floyd();
聽聽聽聽int聽c聽=聽0;
聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽if(color[i]==0)
聽聽聽聽聽聽聽聽聽聽聽聽make_color(i,++c);
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽maxPath[i]聽=聽0;
聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽if(i!=j&&color[i]==color[j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽maxPath[i]聽=聽max(maxPath[i],path[i][j]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽diameter[color[i]]聽=聽max(diameter[color[i]],maxPath[i]);
聽聽聽聽}
聽聽聽聽double聽dia聽=聽DBL_MAX;
聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽for(int聽j=i+1;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽if(color[i]==color[j])聽continue;
聽聽聽聽聽聽聽聽聽聽聽聽double聽d1聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽p=0;p<n;++p){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i!=p&&color[i]==color[p])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽d1聽=聽max(d1,path[i][p]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽double聽d2聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽p=0;p<n;++p){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j!=p&&color[j]==color[p])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽d2聽=聽max(d2,path[j][p]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽double聽dist聽=聽sqrt(聽(x[i]-x[j])*(x[i]-x[j])+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽(y[i]-y[j])*(y[i]-y[j])聽);
聽聽聽聽聽聽聽聽聽聽聽聽dia聽=聽min(dia,max(d1+d2+dist,max(diameter[color[i]],diameter[color[j]]))聽);
聽聽聽聽聽聽聽聽}
聽聽聽聽out.setf(ios::fixed,ios::floatfield);
聽聽聽聽out.precision(6);
聽聽聽聽out<<dia<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>