]]>poj2063--01鑳屽寘http://m.shnenglu.com/hoolee/archive/2012/08/14/187143.html灝忛紶鏍?/dc:creator>灝忛紶鏍?/author>Tue, 14 Aug 2012 03:45:00 GMThttp://m.shnenglu.com/hoolee/archive/2012/08/14/187143.htmlhttp://m.shnenglu.com/hoolee/comments/187143.htmlhttp://m.shnenglu.com/hoolee/archive/2012/08/14/187143.html#Feedback0http://m.shnenglu.com/hoolee/comments/commentRss/187143.htmlhttp://m.shnenglu.com/hoolee/services/trackbacks/187143.html棰樻剰鎻忚堪錛氭湁鍑犵涓嶅悓鐨勫哄埜鍏辮喘涔幫紝姣忕鍊哄埜鏈夌浉搴旂殑騫存晥鐩婏紝榪欎簺鍊哄埜姣忓勾鍙互鍏戠幇涓嬈★紝騫朵笖娌℃湁浠諱綍鎵嬬畫璐癸紝鍏戠幇鍚庡彲浠ラ夋嫨璐拱涓嶅悓鍊哄埜銆傜粰瀹氬垵濮嬮噾棰濆拰騫撮檺錛屾眰鍑烘渶緇堢殑鏈澶ф敹鐩娿?br />瑙i鎬濊礬錛氭瘡騫存寜01鑳屽寘闂璁$畻涓閬嶅嵆鍙?/div>
#include<stdio.h> #include<stdlib.h> #include<string.h> #define LEN 100000 typedef struct { int w; int i; }Bonds; int f[LEN]; Bonds bd[20]; int Max(int a, int b) { if(a > b) return a; return b; } int main() { int i, j, k; int N; int M, Y; int d, a, b; scanf("%d", &N); while(N--) { scanf("%d%d", &M, &Y); scanf("%d", &d); for(i =1; i <= d; i++) { scanf("%d%d", &bd[i].w, &bd[i].i); bd[i].w /=1000;//鍊哄埜鐨勯潰鍊奸兘鏄?000鐨勬暣鏁板?/span> } int alli =0; for(j =0; j < Y; j++) { M += alli; int P = M /1000;//鍊哄埜鐨勯潰鍊奸兘鏄?000鐨勬暣鏁板?/span> memset(f, 0, sizeof(f)); for(i =1; i <= d; i++) for(k = bd[i].w; k <= P; k++) f[k] = Max(f[k], f[k - bd[i].w] + bd[i].i); alli = f[P]; } M += alli; printf("%d\n", M); } //system("pause"); }
]]>poj3624--鏈璧よ8鐨?1鑳屽寘http://m.shnenglu.com/hoolee/archive/2012/08/14/187136.html灝忛紶鏍?/dc:creator>灝忛紶鏍?/author>Tue, 14 Aug 2012 02:44:00 GMThttp://m.shnenglu.com/hoolee/archive/2012/08/14/187136.htmlhttp://m.shnenglu.com/hoolee/comments/187136.htmlhttp://m.shnenglu.com/hoolee/archive/2012/08/14/187136.html#Feedback0http://m.shnenglu.com/hoolee/comments/commentRss/187136.htmlhttp://m.shnenglu.com/hoolee/services/trackbacks/187136.html01鑳屽寘鍘嬬緝鐨勫姩鎬佹柟紼嬩負f[v]=Max(f[v],f[v-Ci]+Wi)銆?br />璇︽儏鍙傞槄銆婅儗鍖呬節璁層嬶細http://wenku.baidu.com/view/519124da5022aaea998f0f22.html 浠ヤ笅鏄湰棰樹唬鐮侊細
#include<stdio.h> #include<stdlib.h> #include<string.h> #define LEN 20000 #define LENN 4000 typedef struct { int w; int d; }Charm; int Max(int a, int b) { if(a > b) return a; return b; } int main() { int i, j; Charm cm[LENN]; int N, M; int f[LEN]; while(scanf("%d%d", &N, &M) != EOF) { for(i =1; i <= N; i++) scanf("%d%d", &cm[i].w, &cm[i].d); memset(f, 0, sizeof(f)); for(i =1; i <= N; i++) for(j = M; j >= cm[i].w; j--) f[j] = Max(f[j], f[j - cm[i].w] + cm[i].d); printf("%d\n", f[M]); } //system("pause"); }
]]>pku1384Piggy-Bank瀹屽叏鑳屽寘http://m.shnenglu.com/hoolee/archive/2012/05/09/174217.html灝忛紶鏍?/dc:creator>灝忛紶鏍?/author>Wed, 09 May 2012 10:23:00 GMThttp://m.shnenglu.com/hoolee/archive/2012/05/09/174217.htmlhttp://m.shnenglu.com/hoolee/comments/174217.htmlhttp://m.shnenglu.com/hoolee/archive/2012/05/09/174217.html#Feedback0http://m.shnenglu.com/hoolee/comments/commentRss/174217.htmlhttp://m.shnenglu.com/hoolee/services/trackbacks/174217.html瀹屽叏鑳屽寘銆?br />瑕佺偣錛?br />1.瑕佹眰浠峰肩殑鏈灝忓?br />2.瑕佹眰鑳屽寘姝eソ瑁呮弧
#include<stdio.h>//pku1384 #include<string.h> #include<stdlib.h> #define LENEF 10010 #define LENNP 510 #define MAX 1000000000 int f[LENEF]; int N, T, E, F; int P[LENNP], W[LENNP]; int min(int a, int b) { if(a < b) return a; return b; } void CPack() { int i, j; int V = F - E; for(i =1; i <= V; i++) f[i] = MAX; f[0] =0; for(i =1; i <= N; i++) { for(j = W[i]; j <= V; j++) f[j] = min(f[j], f[j - W[i]] + P[i]); } } int main() { int i, j; scanf("%d", &T); for(int k =0; k < T; k++) { scanf("%d%d%d", &E, &F, &N); for(i =1; i <= N; i++) scanf("%d%d", &P[i], &W[i]); // //printf("E = %d F = %d N = %d\n", E, F, N); // CPack(); if(f[F - E] != MAX) printf("The minimum amount of money in the piggy-bank is %d.\n", f[F - E]); else printf("This is impossible.\n"); } }
]]>pku3624Charm Bracelethttp://m.shnenglu.com/hoolee/archive/2012/05/08/173968.html灝忛紶鏍?/dc:creator>灝忛紶鏍?/author>Tue, 08 May 2012 01:47:00 GMThttp://m.shnenglu.com/hoolee/archive/2012/05/08/173968.htmlhttp://m.shnenglu.com/hoolee/comments/173968.htmlhttp://m.shnenglu.com/hoolee/archive/2012/05/08/173968.html#Feedback0http://m.shnenglu.com/hoolee/comments/commentRss/173968.htmlhttp://m.shnenglu.com/hoolee/services/trackbacks/173968.html璧よ8瑁哥殑0-1鑳屽寘錛屽緢姘淬傚惉璇寸渷璧涜鍑篋P棰橈紝鎴戜滑闃熶笁涓漢閮戒笉鎿呴暱DP錛屼簬鏄箮鎴戝紑濮嬩粠鑳屽寘闂鍏ユ墜瀛︿範鍔ㄦ佽鍒掋傜湅浜嗗嚑澶╃殑鑳屽寘錛屽ご閮藉ぇ浜嗭紝榪樻槸涓嶇悊瑙o紝浠婂ぉ緇堜簬A鎺変簡涓閬撴按棰橈紝鍊煎緱綰康涓涓嬨?br />鍏充簬鑳屽寘榪欓噷灝變笉澶氳浜嗭紝鎰熷叴瓚g殑绔ラ瀷鍙互鍙傝冦婅儗鍖呴棶棰樹節璁層嬨?/p>
#include<stdio.h> #include<stdlib.h> #include<string.h> #define LEN 14000 int N, M; int W[LEN]; int D[LEN]; int f[LEN]; int max(int a, int b) { if(a > b) return a; else return b; } void bag() { int i, j; for(i =0; i <= N; i++) f[i] =0; for(i =1; i <= N; i++) for(j = M; j >= W[i]; j--) f[j] = max(f[j], f[j - W[i]] + D[i]); } int main() { int i, j; scanf("%d%d", &N, &M); for(i =1; i <= N; i++) { scanf("%d%d", &W[i], &D[i]); } bag(); printf("%d\n", f[M]); //system("pause"); }