看了半天...发现就是个背包...然后就不打算敲了. 看了一眼forum..顿时吓傻..其他人用了gcd啊什么的各种奇怪的东西..然后还是敲了个背包结果就AC了= =既然写了代码就扔上来吧...

------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
 
const int maxn = 1000009;
const int INF = 0X3F3F3F3F;
 
int V[maxn];
int n, N, c[3];
 
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", c + i);
scanf("%d", &N);
memset(V, INF, sizeof V); V[0] = 0;
for(int i = 0; i < n; i++)
for(int v = c[i]; v <= N; v++)
V[v] = min(V[v], V[v - c[i]] + 1);
if(V[N] != INF)
printf("%d\n", V[N]);
else
puts("-1");
return 0;
}

------------------------------------------------------------------------

248. Integer Linear Programming

time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard

You are to solve some problem of integer linear programming. It is posed in the following way. Let x[i] be a variable which is required to be a non-negative integer (for any i from [1..N]). The goal is to minimize the function f(x[1], x[2],..., x[N])=x[1]+x[2]+...+x[N] (objective function) satisfying the constraint c[1]*x[1]+c[2]*x[2]+...+c[N]*x[N]=V. 
The point X=(x[1], x[2],..., x[N]) that satisfies the constraint is called "feasible". All feasible points form a feasible set. 
To make things clear, let us consider the following example N=2, c[1]=2, c[2]=4, V=6. There are only two feasible points: (1, 1) and (3, 0). 
Clearly, the point (1, 1) is the optimal solution, because f(1, 1)<f(3, 0).
Input
The first line of input contains a single positive integer N (0<N<=3). The second line contains N positive integers c[i] separated by whitespaces (0<c[i]<=10^6). The last line contains positive integer V (0<V<=10^6).
Output
On the first line of the output file print the minimal possible value of the function f, or "-1" (without quotes) if the problem has no solution.
Sample test(s)
Input

Test #1 

2 4 
6

Test #2 

7 4 
9

Output

Test #1 
2

Test #2 
-1

Note
See picture: 

Author: Dmitry Filippov (DEF)
Resource: Petrozavodsk Summer Training Sessions 2004
Date: August 25, 2004

SGU 248. Integer Linear Programming( 背包dp )的更多相关文章

  1. hdu 5534 Partial Tree 背包DP

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  2. 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理 状态压缩dp+背包dp

    题目描述 Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Far ...

  3. Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp

    D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...

  4. HDU 5119 Happy Matt Friends (背包DP + 滚动数组)

    题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...

  5. poj 2184 01背包变形【背包dp】

    POJ 2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14657   Accepte ...

  6. Codeforces 922 E Birds (背包dp)被define坑了的一题

    网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...

  7. 背包dp整理

    01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...

  8. HDU 5501 The Highest Mark 背包dp

    The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  9. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

随机推荐

  1. ubuntu系统下设置静态IP

    改动 /etc/network/interfaces文件 加入下面内容 # The loopback network interface auto lo eth0 iface lo inet loop ...

  2. RHEL与Centos

    一直在用centos,但对他的由来以及与RHEL的关系不是很明白,查些资料,小记一番. 倘若一说到Red Hat这个大名,大家似乎都听过. Qustion1:Red Hat家族中有哪些产品呢? Red ...

  3. 学习Java这几个快捷键你得知道(不断更新中)

    java中的System.out.println();的快捷键    --------先输入sysout  在按 alt + /

  4. 《think in python》学习-2

    高能提示:本文大量编程术语与释义,一些释义如有偏差恕不讨论. 变量,表达式 数据类型: print 4 #打印整数 int print 4.1#打印浮点数 float print "hell ...

  5. Sql Server 服务器名称\实例名称 无法连接 Server Name\Instance Name

      解决步骤: 1:  Sql Server是否已经启动. 2:  检查Sql Server服务器是否开启TCP/IP协议. 侦听的默认端口为1433          3:     ping 数据库 ...

  6. VBA基础概念

    一:VBA对象 'VBA对象 'VBA中的对象其实就是我们操作的具有方法.属性的excel中支持的对象 'Excel中的几个常用对象表示方法 '1.工作簿 ' Workbooks 代表工作簿集合,所有 ...

  7. C++中引用用于结构

    正确 void change(test &target) { target.name = "aaa"; } 错误 void change(const test &t ...

  8. flash Builder JSON使用实例

    flash Builder JSON 使用说明(转载houdinime) XML虽然强大但有人觉得xml不够简洁,编码和解码也有一定难度,于是21世纪初有人发明了JSON编码,相比xml内容少并且容易 ...

  9. mysql sql学习(一)mysql连接

    mysql -h 192.168.3.103 -uroot -p123456 //连接数据库 \s :查看数据库状态 show databases; 查看是数据库 create database if ...

  10. Python封装的访问MySQL数据库的类及DEMO

    # Filename:mysql_class.py # Author:Rain.Zen; Date: 2014-04-15 import MySQLdb class MyDb: '''初始化[类似于构 ...