动态规划 POJ 3181 Dollar Dayz
来源:互联网 发布:淘宝肉肉家 编辑:程序博客网 时间:2024/04/28 14:29
POJ 3181 题目链接
题目大意:
给出价值从1-K的货物,问花完N块钱去买这些货物可以有多少种方法。
思路:
很典型的背包问题,用一维数组,不过要用到高精度计算的技巧,不然WA。
ps: 这点在interviewStreet中有用到过,当时是python的大数毫无压力秒过,但是C++要用string来模拟。
解题代码如下:
/* * poj_3181_dollar_dayz.cpp * * Created on: 2013-7-7 * Author: zhengwei */#include <iostream>#include <vector>#include <ostream>#include <algorithm>#include <iterator>#include <cstdio>using namespace std;const int MAX = 100;const int MAX_AMOUNT = 1100;vector<vector<int> > bigDpArray(MAX_AMOUNT, vector<int>(MAX));void computeAdd(int amount, int prevAmount) {for (int i = 0; i <= MAX; i++) {bigDpArray[amount][i] += bigDpArray[prevAmount][i];if (bigDpArray[amount][i] >= 10) {bigDpArray[amount][i] %= 10;bigDpArray[amount][i+1]++;}}}int main () {int totalAmount, denoNum;while (cin >> totalAmount >> denoNum) {fill(bigDpArray.begin(), bigDpArray.end(), vector<int>(MAX, 0));bigDpArray[0][0] = 1;for (int i = 1; i <= denoNum; i++) {for (int j = i; j <= totalAmount; j++) {computeAdd(j, j-i);}}int colNum = MAX-1;while (bigDpArray[totalAmount][colNum] == 0 && colNum >= 0) {colNum --;}for (; colNum >= 0; colNum --) {cout << bigDpArray[totalAmount][colNum];}cout << endl;}}
- 动态规划 POJ 3181 Dollar Dayz
- POJ 3181 -- Dollar Dayz(动态规划)
- poj 3181 Dollar Dayz 题解(动态规划)
- POJ 3181 Dollar Dayz 动态规划法题解
- poj 3181 Dollar Dayz
- POJ 3181 Dollar Dayz
- Poj 3181 Dollar Dayz
- POJ 3181 Dollar Dayz
- poj 3181 Dollar Dayz
- poj 3181 Dollar Dayz
- POJ 3181 Dollar Dayz
- poj 3181 Dollar Dayz
- poj 3181 Dollar Dayz
- POJ-3181-Dollar Dayz
- POJ 3181 Dollar Dayz
- poj 3181 Dollar Dayz
- poj 3181 Dollar Dayz
- POJ 3181 Dollar Dayz
- UNIX环境高级编程——进程间通信概念
- ftp服务器的搭建
- STL算法简介
- UNIX环境高级编程——信号说明列表
- 创建html表单,有格式要求和必填项要求
- 动态规划 POJ 3181 Dollar Dayz
- x264参数与代码对应
- Java中ArrayList类的用法(转)
- 复写一个ListView
- 图数据库Neo4J的使用
- 数组操作
- android 中发送短信
- 证件照蓝底变白底的方法
- 黑马程序员_JAVA1.5新特性——静态导入