ZOJ 3689 Digging(C语言版)

本文探讨了一个结合了Maya文明背景的01背包问题,通过将工程按价值排序并应用01背包算法求解最大收益,提供了一种解决实际问题的创新思路。
Digging

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 BabylonianhasAncient 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 ith coffin 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 ithcoffin 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 NT (1 ≤ N ≤ 3000,1 ≤ T ≤ 10000), indicating there are N coffin chambers to be built, and there are T days for workers working. Next N lines containstisi (1 ≤ tisi ≤ 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

这题非常有意思,虽然知道要用到01背包,但是还是很难做出。

因为所取的物品按不同的顺序排放会得到不同的价值。

思路是先将各物品排好顺序,再用01背包考虑取和不取。(这里的物品为一个工程)

用t[i],s[i]表示这个工程的耗时和工程面积。

考虑任意两个相邻位置的工程,注意到这两个工程交换位置不会影起其它工程所获价值的变化。

那么假设此时剩l天。value1=l*s[i]+(l-t[i])*s[i+1];

若交换这两个工程:value2=l*s[i+1]+(l-t[i+1])*s[i];

value2-value1=t[i]*s[i+1]-t[i+1]*s[i];

若这个差大于0,则表明安排工程时应将i+1这个工程放在i前面。理解为工程i+1比i更有价值。

所以我们在选择前把所有的工程按“价值”的从高到低排序。

再用01背包考虑最优解。

这里需要注意的是因为我们把“高价值”的工程先考虑,所以理解背包dp方程时

f[v-c[i]]理解为在天数为v-c[i]天的工程表“后”插入该工程。(这句话仔细理解)

普通的01背包没有考虑在放入物品时背包的状态,而此题需要我们弄清。

贴上AC代码:

#include<stdio.h>
int f[10001];
int main()
{
int v,n,T,t[3001],s[3001],i,j,k,temp,max;
while(scanf("%d%d",&n,&T)!=EOF)
{
for(i=1;i<=n;i++)
scanf("%d%d",&t[i],&s[i]);
for(i=1;i<=T;i++)
f[i]=0;
for(i=1;i<n;i++)
{
for(j=1;j<=n-i;j++)
{
k=j+1;
if(t[j]*s[k]>s[j]*t[k])
{
temp=t[j];
t[j]=t[k];
t[k]=temp;
temp=s[j];
s[j]=s[k];
s[k]=temp;
}
}
}
for(i=1;i<=n;i++)
{
for(v=T;v>=t[i];v--)
{
j=f[v-t[i]]+(T-v+t[i])*s[i];//(T-v+t[i])表示剩余天数,因为此工程插在(v-c[i])天的工程表后。
if(f[v]<j)
f[v]=j;
}
}
max=0;
for(i=0;i<=T;i++)//最后需要遍历一下是因为物品的插入位置不确定。
if(f[i]>max)
max=f[i];
printf("%d\n",max);
}
return 0;
}

Nano-ESG数据资源库的构建基于2023年初至2024年秋季期间采集的逾84万条新闻文本,从中系统提炼出企业环境、社会及治理维度的信息。其构建流程首先依据特定术语在德语与英语新闻平台上检索,初步锁定与德国DAX 40成分股企业相关联的报道。随后借助嵌入技术对文本段落执行去重操作,以降低内容冗余。继而采用GLiNER这一跨语言零样本实体识别系统,排除与目标企业无关的文档。在此基础上,通过GPT-3.5与GPT-4o等大规模语言模型对文本进行双重筛选:一方面判定其与ESG议题的相关性,另一方面生成简明的内容概要。最终环节由GPT-4o模型完成,它对每篇文献进行ESG情感倾向(正面、中性或负面)的判定,并标注所涉及的ESG具体维度,从而形成具备时序特征的ESG情感与维度标注数据集。 该数据集适用于多类企业可持续性研究,例如ESG情感趋势分析、ESG维度细分类别研究,以及企业可持续性事件的时序演变追踪。研究者可利用数据集内提供的新闻摘要、情感标签与维度分类,深入考察企业在不同时期的环境、社会及治理表现。此外,借助Bertopic等主题建模方法,能够从数据中识别出与企业相关的核心ESG议题,并观察这些议题随时间的演进轨迹。该资源以其开放获取特性与连续的时间覆盖,为探究企业可持续性表现的动态变化提供了系统化的数据基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值