E - Thief in a Shop

题目大意:给你n ( n <= 1000)个物品每个物品的价值为ai (ai <= 1000),你只能恰好取k个物品,问你能组成哪些价值。

思路:我们很容易能够想到dp[ i ][ j ]表示取i次j是否存在,但是复杂度1e12肯定不行。

我们将ai排序,每个值都减去a[1]然后再用dp[ i ]表示到达i这个值最少需要取几次,只需要1e9就能完成,

我们扫一遍dp数组,如果dp[ i ]  <= k 则说明 i + k * a[1]是能取到的。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> > using namespace std; const int N = 1e3 + ;
const int M = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int dp[N * N], a[N], n, k;
int main() {
memset(dp, inf, sizeof(dp));
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]); sort(a + , a + n + ); for(int i = ; i <= n; i++)
a[i] -= a[]; dp[] = ; for(int i = ; i <= ; i++) {
for(int j = ; j <= n; j++) {
if(a[j] + i > ) continue;
dp[i + a[j]] = min(dp[i + a[j]], dp[i] + );
}
} for(int i = ; i <= ; i++) {
if(dp[i] <= k) {
printf("%d ", i + a[] * k);
}
}
puts("");
return ;
}
/*
*/

codeforces Educational Codeforces Round 9 E - Thief in a Shop的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Educational Codeforces Round 9 E. Thief in a Shop dp fft

    E. Thief in a Shop 题目连接: http://www.codeforces.com/contest/632/problem/E Description A thief made hi ...

  4. Educational Codeforces Round 9 E. Thief in a Shop NTT

    E. Thief in a Shop   A thief made his way to a shop. As usual he has his lucky knapsack with him. Th ...

  5. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  6. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  7. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  8. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  9. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. 前端路由的两种模式: hash 模式和 history 模式

    随着 ajax 的使用越来越广泛,前端的页面逻辑开始变得越来越复杂,特别是spa的兴起,前端路由系统随之开始流行. 从用户的角度看,前端路由主要实现了两个功能(使用ajax更新页面状态的情况下): 记 ...

  2. bzoj千题计划148:bzoj1537: [POI2005]Aut- The Bus

    http://www.lydsy.com/JudgeOnline/problem.php?id=1537 朴素的转移:dp[i][j]=max(dp[i][j-1],dp[i-1][j])+p[i][ ...

  3. 1130 N的阶乘的长度 V2(斯特林近似)

    1130 N的阶乘的长度 V2(斯特林近似) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 输入N求N的阶乘的10进制表示的长度.例如6! = 720, ...

  4. [译]Quartz.NET 框架 教程(中文版)2.2.x 之第五课 SimpleTrigger

    第五课 SimpleTrigger 如果你需要在一个指定时间段内执行一次作业任务或是在指定的时间间隔内多次执行作业任务,SimpleTrigger应该能满足你的调度需求.例如,你希望触发器在2015年 ...

  5. 网摘关于BarCodeControl控件

    简介 BarCodeControl是一个用户制作条形码的控件. MicrosoftBarcodeControl9.0是可以在MicrosoftOfficeAccess窗体和报表中显示条码符号的Acti ...

  6. #error#优化#Model#理解下面这句话错误所导致的错误:"传入一个对象,那么你就拥有了对象的属性"2

    CHENYILONG Blog #error#优化#Model#理解下面这句话错误所导致的错误:"传入一个对象,那么你就拥有了对象的属性"2 © chenyilong. Power ...

  7. HDU 1994 利息计算 数学题

    解题报告:算利息的,不过一开始格式控制符里面少写了一个%lf,一直没看到,愣是没找到错误,唉! #include<cstdio> int main() { int T; scanf(&qu ...

  8. xampp + windows 配置 memcache流程

    1.运行xampp服务,打开phpinfo查看信息,如下图: 从上到下,依次为 PHP版本:5.6: architecture:x86: TS:线程安全: vc11 2.牢记以上几个横线内容之后去下载 ...

  9. base64 与字符串互转

    #region 将Base64编码的文本转换成普通文本 /// <summary> /// 将Base64编码的文本转换成普通文本 /// </summary> /// < ...

  10. linux学习记录.5.git & github

    参考 https://www.linuxidc.com/Linux/2016-11/136769.htm 安装 安装 Git: apt-get install git 查看当前版本: git --ve ...