G - Animals

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

input

input.txt

output

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

Input
3 4
1 1 1
Output
2
Input
3 6
1 1 1
Output
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的更多相关文章

  1. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals

    D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...

  2. Codeforces 713D Animals and Puzzle(二维ST表+二分答案)

    题目链接 Animals and Puzzle 题意  给出一个1e3 * 1e3的01矩阵,给出t个询问,每个询问形如x1,y1,x2,y2 你需要回答在以$(x1, y1)$为左上角,$(x1, ...

  3. Codeforces 713D Animals and Puzzle

    题意:一个n*m的01矩阵,Q个询问,每次询问一个矩形区域内,最大的全1正方形的边长是多少? 题解:dp[0][0][i][j]表示以(i, j)为右下角的正方形的最长边长.RMQ后,二分答案即可. ...

  4. CodeForces - 35D

    题目:https://vjudge.net/contest/326867#problem/A 题意:有一个农场,自己有m斤粮食,有n天,每天动物吃的量不同,那个动物的食量的是由他是从那天开始进这个农场 ...

  5. CF dp 题(1500-2000难度)

    前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...

  6. 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 ...

  7. 【CodeForces】713 D. Animals and Puzzle 动态规划+二维ST表

    [题目]D. Animals and Puzzle [题意]给定n*m的01矩阵,Q次询问某个子矩阵内的最大正方形全1子矩阵边长.n,m<=1000,Q<=10^6. [算法]动态规划DP ...

  8. 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 ...

  9. codeforces 713D D. Animals and Puzzle 二分+二维rmq

    题目链接 给一个01矩阵, 然后每个询问给出两个坐标(x1, y1), (x2, y2). 问你这个范围内的最大全1正方形的边长是多少. 我们dp算出以i, j为右下角的正方形边长最大值. 然后用二维 ...

随机推荐

  1. leetcode mock Shuffle an Array

    1. shuffle算法: http://www.cnblogs.com/huaping-audio/archive/2008/09/09/1287985.html 注意:我们一般用的是第二种swap ...

  2. 关闭使用ShellExecute打开的进程!!!!!

    前言: 最近做一个项目使用到ShellExecute来打开一个带参数的外部exe文件,关闭时遇到不少问题,最终解决,总结如下. 对于关闭ShellExecute打开的进程窗口,网上比较多的是用Find ...

  3. C# 窗体WinForm中动态显示radioButton实例

    一个项目中用到的实例,根据数据库查询出待显示的radioButton的个数,显示在一个新的窗口中. //动态显示radioButton public void showRadioButton(int ...

  4. 在weka中添加libSVM或者HMM等新算法

    转:http://kasy-13.blog.163.com/blog/static/8214691420143226365887/ Weka的全名是怀卡托智能分析环境(Waikato Environm ...

  5. CSS中:before和:after选择器的用法

    在线演示这次给大家带来的是对话气泡效果,主要是演示了 :before / :after 和 border 的用法,赶快来围观吧. 阅读原文:CSS中:before和:after选择器的用法

  6. 一个完整的C++程序SpreadSheet - 1) 类的声明和定义

    1. SpreadsheetCell.h #pragma once #include <string> class SpreadsheetCell { public: void setVa ...

  7. HDU 1565 1569 方格取数(最大点权独立集)

    HDU 1565 1569 方格取数(最大点权独立集) 题目链接 题意:中文题 思路:最大点权独立集 = 总权值 - 最小割 = 总权值 - 最大流 那么原图周围不能连边,那么就能够分成黑白棋盘.源点 ...

  8. HDU 5312(数学推导+技巧)

    首先说一下.N*(N-1)/2为三角形数,随意一个自然数都最多可由三个三角形数表示. 对于,对于给定的要求值 V, 那么其一组解可表示为 V = 6*(K个三角形数的和)+K: 即随意由k个数组成的解 ...

  9. 彻底告别加解密模块代码拷贝-JCE核心Cpiher详解

    前提 javax.crypto.Cipher,翻译为密码,其实叫做密码器更加合适.Cipher是JCA(Java Cryptographic Extension,Java加密扩展)的核心,提供基于多种 ...

  10. No implementation found for long com.baidu.platform.comjni.map.commonmemcache.JNICommonMemCache.Create()

    3-21 10:14:20.833 2892-2892/? E/art: No implementation found for long com.baidu.platform.comjni.map. ...