HDU 1681 Frobenius(完全背包+标记装满)
一个完全背包,数组两百万,暴力可过
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 2000010
int dp[maxn];
int main()
{
int t,w[];
scanf("%d",&t);
while(t--)
{
for(int i = ;i < ;i++)
scanf("%d",&w[i]);
memset(dp,0x3f,sizeof(dp));
dp[] = ;
int all = ;
for(int i = ;i < ;i++)
{
for(int j = w[i];j < all;j++)
dp[j] = min(dp[j],dp[j-w[i]] + );
}
int sum = ,ans = ;
for(int i = ;i <= ;i++)
{
if(dp[i] >= 0x3f3f3f)
{
sum++;
ans = i;
}
}
bool mark = true;
for(int i = ;i <= ;i++)
{
if(dp[i] >= 0x3f3f3f)
{
mark = false;
break;
}
}
if(mark)
printf("%d\n%d\n",sum,ans);
else printf("%d\n%d\n",sum,-);
}
return ;
}
HDU 1681 Frobenius(完全背包+标记装满)的更多相关文章
- HDU 1681 Frobenius
题目链接:Frobenius 思路:想了很久还是没转过弯来. 递推. 初始化vis[0] = 1,每次有四种方法扩展,这样能扩展到所有能被表示的数.上界的判定,如果一万以内的数都能被表示,那以后的数肯 ...
- 题解报告:hdu 1114 Piggy-Bank(完全背包恰好装满)
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- hdu 2546 典型01背包
分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...
- HDU 3127 WHUgirls(完全背包)
HDU 3127 WHUgirls(完全背包) http://acm.hdu.edu.cn/showproblem.php? pid=3127 题意: 如今有一块X*Y的矩形布条, 然后有n种规格的x ...
- HDU 1114 【完全背包裸题】
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU - 1114 Piggy-Bank 完全背包(背包恰好装满)
Piggy-Bank Before ACM can do anything, a budget must be prepared and the necessary financial support ...
- 杭电1171 Big Event in HDU(母函数+多重背包解法)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu -1114(完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 思路:求出存钱罐装全部装满情况下硬币的最小数量,即求出硬币的最小价值.转换为最小背包的问题. # ...
- HDU 3535 分组混合背包
http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n组工作,T时间,每个工作组中有m个工作,改组分类是s,s是0是组内至少要做一件,是1时最多做一件 ...
随机推荐
- SDK does not contain any platforms. error (android)
By default sdk was installed under the C:\Users\<user_name>\AppData\Local\Android\sdk\ directo ...
- Error establishing socket解决办法
jdbc配置语句为: jdbc:microsoft:sqlserver://server_name:1433 如运行程序时出现 "Error establishing socket" ...
- Tomcat 启动报错:javax.naming.NamingException: No naming context bound to this class loader
分析原因:在类中使用了Log .只是在项目lib路径下添加了slf4 的jar包,在Tomcat\lib下未添加 解决方案:将slf4的jar包放到tomcat\lib下.
- 基于Flash ActionScript 实现RTMP发布与播放媒本流
1 为什么要采用Flash ActionScript实现RTMP协议发布或播放媒体流,播放媒体流,协议可控,比如对流媒体数加密,混音等. 2 核心思路使用Flash Socket建立TCP二进制传输 ...
- perl版 Webshell存活检测
原理: 检测url返回状态即可 源码: #!c:\\perl\\bin\\perl.exe use warnings; use strict; use LWP::UserAgent; $| = ; p ...
- postgresql删除属性
PostgreSQL update and delete property from JSONB column up vote 2 down vote favorite From this artic ...
- sql 将表B中不存在表A的数据 插入到表A中
insert into tableA select * from tableB b where not exists(select 1 from tableA a where a.id = b.id) ...
- [笔记]Practical Lessons from Predicting Clicks on Ads at Facebook
ABSTRACT 这篇paper中作者结合GBDT和LR,取得了很好的效果,比单个模型的效果高出3%.随后作者研究了对整体预测系统产生影响的几个因素,发现Feature+Model的贡献程度最大,而其 ...
- Chapter 2 Open Book——10
I sent that, and began again. 我发送了它,然后又一次重新开始写了. Mom,Everything is great. Of course it's raining. I ...
- [转]Publishing and Running ASP.NET Core Applications with IIS
本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...