ps:動態規劃 -裝箱
#include<stdio.h>
#include<stdlib.h>
struct fun
{
int p,m;
}a[105];
int cmp(const void*a,const void *b)
{
struct fun *c=(struct fun*)a,*d=(struct fun*)b;
return d->p-c->p;
}
int main()
{
int v,n,i,tol;
while(scanf("%d%d",&v,&n)!=EOF&&v!=0)
{
tol=0;
for(i=0;i<n;i++)
scanf("%d%d",&a[i].p,&a[i].m);
qsort(a,n,sizeof(a[0]),cmp);
for(i=0;i<n;i++)
{
if(a[i].m<=v)
{
tol+=a[i].p*a[i].m;
v-=a[i].m;
}
else
{
tol+=a[i].p*v;
v=0;
}
}
printf("%d\n",tol);
}
return 0;
}
hdu 2111 Saving HDU (DP)
轉載於:https://www.cnblogs.com/yyf573462811/archive/2012/09/02/6365222.html
相關文章
- hdu 6415 - DP
- HDU1024(dp)
- HDU6415(DP)
- HDU 6415 (計數dp)
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- HDU 6035 Colorful Tree(樹形DP)
- HDU 1074 Doing Homework(狀壓DP)
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- HDU4652 Dice(期望dp推式子)
- HDU 6415(dp/記憶化搜尋)
- HDU多校第九次 6415 (dp
- HDU 5816 Hearthstone(狀態壓縮DP+概率)
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- 【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415UI
- hdu--5418Victor and World+狀態壓縮DP
- 「暑期訓練」「基礎DP」 Monkey and Banana (HDU-1069)NaN
- HDU7458-啟發式合併最佳化DP
- Shape of HDU
- HDU 3349
- HDU 2052(C語言+註釋)+HDU 2090C語言
- hdu--4455+ Substrings+2012杭州區域賽C題+DP
- 「暑期訓練」「基礎DP」免費餡餅(HDU-1176)
- HDU 6415(dp/找規律-2018多校第九場1001)
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- HDU 1240 Asteroids!AST
- hdu2083
- hdu5532
- HDU4787
- hdu5540
- HDU 4921 Map
- HDU 3661 Assignments
- HDU 1729 Stone GameGAM
- HDU 3590 PP and QQ
- HDU 2570 迷瘴
- hdu1069javaJava
- hdu1025javaJava
- HDU Find the hotel(RMQ)MQ
- HDU 6060 RXD and dividing