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为右下角的正方形边长最大值. 然后用二维 ...
随机推荐
- sqlmap的篡改绕过WAF
space2comment.py Replaces space character (‘ ‘) with comments ‘/**/’ Example: * Input: SELECT id FRO ...
- c#如何操作ppt的播放 【转】
C#控制ppt的代码 包括打开ppt文件.读取幻灯页,插入幻灯片,自动播放等 using System.Collections.Generic; using System.Linq; using Sy ...
- c# 使用api函数 ShowWindowAsync 控制窗体
1.需要匯入 System.Runtime.InteropServices 命名空間 2.宣告 ShowWindowAsync 函數 [DllImport("user32.dll" ...
- 论#include
1.#include " "与#include <> #include " "表示预编译命令源程序在当前项目下寻找头文件,如果找不到,再到标准头文件 ...
- (转)Session URL重写
Session URL重写 发表于 2012 年 3 月 5 日 Session URL重写,保证在客户端禁用或不支持COOKIE时,仍然可以使用Session session机制.session机制 ...
- UI设计经常使用站点
前期:http://www.zcool.com.cn/ 中期:http://www.ui.cn/ 后期:https://dribbble.com/
- rtsp摘要认证协议(Response计算方法)
rtsp摘要认证协议(Response计算方法) 说明: 例如:OPTIONS rtsp://192.168.123.158:554/11RTSP/1.0 RTSP客户端应该使用username ...
- studio快捷键
- excel 快速比对两列数据差异
excel 快速比对两列数据差异 CreateTime--2018年5月31日11:19:35 Author:Marydon 1.情景展示 找出两列数据的差异 2.具体操作 方式一:使用条件格式 ...
- LOL电影天堂下载攻略
LOL电影天堂&&飘花电影网下载攻略 CreateTime--2017年7月27日08:52:29Author:Marydon 以进击的巨人为例 下载地址:http://www.l ...