CodeForces 35D Animals
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
input.txt
output.txt
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.
DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly n days in DravDe’s dream and the animal that came on the i-th day, ate exactly ci tons of food daily starting from day i. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly X tons of food on the farm.
DravDe woke up terrified...
When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the n-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.
It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the n-th.
Input
The first input line contains integers n and X (1 ≤ n ≤ 100, 1 ≤ X ≤ 104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers ci (1 ≤ ci ≤ 300). Numbers in the second line are divided by a space.
Output
Output the only number — the maximum possible amount of animals on the farm by the end of the n-th day given that the food was enough for everybody.
Sample Input
3 4
1 1 1
2
3 6
1 1 1
3
Hint
Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.
#include<iostream>
#include<cstdio>
#include<fstream>
using namespace std; int ani[];
int dp[];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,x;
cin>>n>>x;
//scanf("%d%d",&n,&x);
for(int i=; i<=n; i++)
{
scanf("%d",&ani[i]);
ani[i]*=(n-i+);
}
for(int i=;i<=n;i++)
for(int j=x;j>=ani[i];j--)
dp[j]=max(dp[j],dp[j-ani[i]]+);
//printf("%d\n",dp[x]);
cout<<dp[x]<<endl;
return ;
}
这道题可以dp,也可以贪心。贪心的想法比较简单。按照消耗从小到大排序,从小的开始拿就可以了。
dp的思想是:
dp[x]=max(dp[x],dp[x-ani[i]+1];
dp[x]表示粮食为x时,最多可以收留的动物数。
CodeForces 35D Animals的更多相关文章
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals
D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...
- Codeforces 713D Animals and Puzzle(二维ST表+二分答案)
题目链接 Animals and Puzzle 题意 给出一个1e3 * 1e3的01矩阵,给出t个询问,每个询问形如x1,y1,x2,y2 你需要回答在以$(x1, y1)$为左上角,$(x1, ...
- Codeforces 713D Animals and Puzzle
题意:一个n*m的01矩阵,Q个询问,每次询问一个矩形区域内,最大的全1正方形的边长是多少? 题解:dp[0][0][i][j]表示以(i, j)为右下角的正方形的最长边长.RMQ后,二分答案即可. ...
- CodeForces - 35D
题目:https://vjudge.net/contest/326867#problem/A 题意:有一个农场,自己有m斤粮食,有n天,每天动物吃的量不同,那个动物的食量的是由他是从那天开始进这个农场 ...
- CF dp 题(1500-2000难度)
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...
- Codeforces Round #371 (Div. 1) D. Animals and Puzzle 二维倍增
D. Animals and Puzzle 题目连接: http://codeforces.com/contest/713/problem/D Description Owl Sonya gave a ...
- 【CodeForces】713 D. Animals and Puzzle 动态规划+二维ST表
[题目]D. Animals and Puzzle [题意]给定n*m的01矩阵,Q次询问某个子矩阵内的最大正方形全1子矩阵边长.n,m<=1000,Q<=10^6. [算法]动态规划DP ...
- Codeforces Round #371 (Div. 1) D - Animals and Puzzle 二维ST表 + 二分
D - Animals and Puzzle #include<bits/stdc++.h> #define LL long long #define fi first #define s ...
- codeforces 713D D. Animals and Puzzle 二分+二维rmq
题目链接 给一个01矩阵, 然后每个询问给出两个坐标(x1, y1), (x2, y2). 问你这个范围内的最大全1正方形的边长是多少. 我们dp算出以i, j为右下角的正方形边长最大值. 然后用二维 ...
随机推荐
- cocob优化算法
cocob算法是一个启发式的算法,针对SGD不需要设置learning rate. https://github.com/bremen79/cocob
- go语言基础之格式化输出
1.fmt包的格式化输出输入 格式说明 格式 含义 %% 一个%字面量 %b 一个二进制整数值(基数为2),或者是一个(高级的)用科学计数法表示的指数为2的浮点数 %c 字符型.可以把输入的数字按照A ...
- Node.js:EventEmitter类
一.EventEmitter 类 Node.js 所有的异步 I/O 操作在完成时都会发送一个事件到事件队列. Node.js里面的许多对象都会分发事件:一个net.Server对象会在每次有新连接时 ...
- Python基础(12)--模块
本文地址:http://www.cnblogs.com/archimedes/p/python-modules.html,转载请注明源地址. 模块简介 如果你退出 Python 解释器重新进入,以前创 ...
- EasyUI datagrid 明细表格中编辑框 事件绑定 及灵活计算 可根据此思路 扩展其他
原创 : EasyUI datagrid 明细表格中编辑框 事件绑定 及灵活计算 可根据此思路 扩展其他 转载,请注明出处哦!谢谢! 原创 : EasyUI datagrid 明细表格中编辑框 事件绑 ...
- Python 爬虫 之 阅读呼叫转移(三)
尽管上一篇博客中我们能够连续地阅读章节了,可是.难道每一次看小说都执行一下我们的 Python 程序?连记录看到哪里都不行,每次都是又一次来过?当然不能这样,改! 如今这么多小说阅读器,我们仅仅须要把 ...
- netlink error: too many arguments to function 'netlink_kernel_create'
2.6版本的 netlink_kernel_create(&init_net, NETLINK_TEST, 0, NULL, kernel_receive ,THIS_MODULE); 3 ...
- discuz,ecshop的伪静态规则(apache+nginx)
discuz(nginx): (备注:该规则也适用于二级目录) rewrite ^([^\.]*)/topic-(.+)\.html$ $/portal.php?mod=topic&topic ...
- Android程序怎么做单元测试
如何进行Android单元测试 Menifest.xml中加入: <application>中加入: <uses-library android:name="android ...
- KineticJS教程(5)
KineticJS教程(5) 作者: ysm 5.事件响应 5.1.图形的事件响应 图形对象对事件的响应处理可以使用 on() 方法绑定事件类型和相应方法. On() 方法需要一个事件类型参数和相应 ...