CodeForces - 35D
题目:https://vjudge.net/contest/326867#problem/A
题意:有一个农场,自己有m斤粮食,有n天,每天动物吃的量不同,那个动物的食量的是由他是从那天开始进这个农场确定的,后面不能再变,从这天进来后就必须吃到第n天,每天只能进来一个动物,问最后能被保留下来的动物数最大是多少
思路:
1.贪心+排序,既然他每天只能进入一个动物,而且动物进来后食量不变,而且进来知道吃多少天,那么相当于我们知道所有动物的消费粮食值是多少个,然后我们直接排序,选取最少的那几个即可 O(nlogn)
#include<bits/stdc++.h>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll a[maxn],n,m;
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>a[i];
a[i]=a[i]*(n-i+);
}
sort(a+,a+n+);
int num=;
for(int i=;i<=n;i++){
if(m>=a[i]){
m-=a[i];
num++;
}
else break;
}
printf("%d",num);
}
2.DP ,一样和上面,我们可以知道每个动物的消费粮食值,我们可以转化为一个01背包问题, O(n*m),主要还是当dp题来练手
#include<bits/stdc++.h>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll a[maxn],n,m;
ll dp[maxn];
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>a[i];
a[i]=a[i]*(n-i+);
}
for(int i=;i<=n;i++){
for(int j=m;j>=a[i];j--){
dp[j]=max(dp[j],dp[j-a[i]]+);
}
}
printf("%d",dp[m]);
}
CodeForces - 35D的更多相关文章
- CodeForces 35D Animals
G - Animals Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals
D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- How to use Nlog for ASP.NET Core with csproj
1. Add dependency in csproj manually or using NuGet Install the latest: NLog.Web.AspNetCore 4.5+ Upd ...
- Flask使用原生sql语句
安装pip install flask-sqlalchemy 创建数据库对象 # 设置数据库连接地址app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://r ...
- C#MessageBox 自动关闭窗口
1:MessageBox弹出的模式窗口会先阻塞掉它的父级线程.所以我们可以考虑在MessageBox前先增加一个用于"杀"掉MessageBox窗口的线程.因为需要在规定时间内&q ...
- String.indexOf()的使用方法
String.indexOf()的用途: 返回此字符串中第一个出现的指定的子字符串,如果没有找到则返回-1 源码如下: /** * Returns the index within this stri ...
- HDU 1494 题解(DP)
题面: 跑跑卡丁车 Problem Description 跑跑卡丁车是时下一款流行的网络休闲游戏,你可以在这虚拟的世界里体验驾驶的乐趣.这款游戏的特别之处是你可以通过漂移来获得一种 加速卡,用这种加 ...
- 一键生成APK
傻瓜式的生成APK网址:https://www.appbsl.com/ 第一步 第二步 第三步 第四步
- 动画可以暂停animation-play-state
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- python RE表达式规则剩余规则
前面我学习了 ’.‘ '^' '$' '*' '+' '?' 基本针对单个字符的,学习python 表达式规则剩余规则. 1,{m} 匹配前一个字符m次 2,{n,.m} 匹配前一个字符n到m次 3 ...
- wikioi 2144 分步二进制枚举+map记录
题目描写叙述 Description 有n个砝码,如今要称一个质量为m的物体,请问最少须要挑出几个砝码来称? 注意一个砝码最多仅仅能挑一次 输入描写叙述 Input Description 第一行两个 ...
- 收集慕课网讲解的border知识
1.使用boeder辅助background-posi定位 2.使用border实现三道杠图标 3.利用border实现--鼠标放上去后,改变图标的颜色