四月八号训练
写挂的题
I - SDG ZOJ - 3689
Digging
When it comes to the Maya Civilization, we can quickly remind of a term called the end of the world. It’s not difficult to understand why we choose to believe the prophecy (or we just assume it is true to entertain ourselves) if you know the other prophecies appeared in the Maya Calendar. For instance, it has accurately predicted a solar eclipse on July 22, 2009.
The ancient civilization, such as Old Babylonianhas, Ancient Egypt and etc, some features in common. One of them is the tomb because of the influence of the religion. At that time, the symbol of the tomb is the pyramid. Many of these structures featured a top platform upon which a smaller dedicatory building was constructed, associated with a particular Maya deity. Maya pyramid-like structures were also erected to serve as a place of interment for powerful rulers.
Now there are N coffin chambers in the pyramid waiting for building and the ruler has recruited some workers to work for T days. It takes ti days to complete the ithcoffin chamber. The size of the ith coffin chamber is si. They use a very special method to calculate the reward for workers. If starting to build the ith coffin chamber when there are t days left, they can get t*si units of gold. If they have finished a coffin chamber, then they can choose another coffin chamber to build (if they decide to build the ith coffin chamber at the time t, then they can decide next coffin chamber at the time t-ti).
At the beginning, there are T days left. If they start the last work at the time t and the finishing time t-ti < 0, they will not get the last pay.
Input
There are few test cases.
The first line contains N, T (1 ≤ N ≤ 3000,1 ≤ T ≤ 10000), indicating there are N coffin chambers to be built, and there are T days for workers working. Next Nlines contains ti, si (1 ≤ ti, si ≤ 500).
All numbers are integers and the answer will not exceed 2^31-1.
Output
For each test case, output an integer in a single line indicating the maxminal units of gold the workers will get.
Sample Input
3 10
3 4
1 2
2 1
Sample Output
62
Hint
Start the second task at the time 10
Start the first task at the time 9
Start the third task at the time 6
The answer is 102+94+6*1=62
题目大意:有n个建筑需要修建,工人工作m天,第i个建筑需要修ti天,大小为si ,如果可以在m天内修完第i个建筑就可以获得si*j的黄金,问最多可以获得多少黄金(j是开始修这个建筑是所剩的天数),如果一个建筑不能修完只修到一半是不能获得黄金的
思路:在任意相同时间j下,a先b后与b先a后所能获得的赏金分别是 j * a.s + ( j - a.t ) * b.s 和 j * b.s + ( j - b.t ) * a.s 。其差为 a.s * b.t - a.t * b.s , 反映了每个方案的价性比,如果差值 大于0 说明 a先的性价比高,所以我们按照 a.s*b.t < b.s *a.t 对建筑进行排序,按性价比从底到高排序,由于n个建筑不一定会盖完,所以这里还要进行一次0-1背包
————————————————
版权声明:本文为优快云博主「YOONGI」的原创文章
原文链接:https://blog.youkuaiyun.com/chimchim04/article/details/89192107
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int n,m;
struct qw{
int si,ti;
}side[3002];
int dp[20000];
bool cmp(qw a,qw b){return a.si*b.ti<b.si*a.ti;}
int main(){
int a,b,c,d;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,0,sizeof(dp));
for(a=1;a<=n;a++)
scanf("%d%d",&side[a].ti,&side[a].si);
sort(side+1,side+n+1,cmp);
for(a=1;a<=n;a++)
{
for(b=m;b>=side[a].ti;b--)
dp[b]=max(dp[b],dp[b-side[a].ti]+side[a].si*b);
}
printf("%d\n",dp[m]);
}
return 0;
}
本文探讨了一个涉及建筑修建的算法问题,通过分析不同建筑的修建时间和大小,利用特殊计算方法确定工人的最佳工作计划,以最大化在限定时间内获取的黄金单位数。采用性价比排序和0-1背包算法解决此问题。
7827

被折叠的 条评论
为什么被折叠?



