poj Dollar Dayz(完全背包)

简介: 点击打开链接poj 3181 思路: 完全背包+高精度 分析: 1 题目是裸的完全背包,但是要注意的一个地方是要用高精度 代码: #include#include#include#includeusing namespa...

点击打开链接poj 3181

思路: 完全背包+高精度
分析:
1 题目是裸的完全背包,但是要注意的一个地方是要用高精度


代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 110;
const int MAXN = 1010;

int sum , n , v[N];
int dp[MAXN][N];

void init(){
    for(int i = 1 ; i < N ; i++)
       v[i] = i;
}

void add(int x , int y){
    for(int i = 0 ; i < N ; i++){
        dp[x][i] += dp[y][i];
        dp[x][i+1] += dp[x][i]/10;
        dp[x][i] %= 10;
    } 
}

void solve(){
    memset(dp , 0 , sizeof(dp));
    dp[0][0] = 1;
    for(int i = 1 ; i <= n ; i++)
        for(int j = v[i] ; j <= sum ; j++)
            add(j , j-v[i]);
    int pos = N-1;
    while(!dp[sum][pos])
        pos--;
    for(; pos >= 0 ; pos--)
        printf("%d" , dp[sum][pos]);
    puts("");
}

int main(){
    init();
    while(scanf("%d%d", &sum , &n) != EOF)
        solve();
    return 0;
}




目录
打赏
0
0
0
0
15
分享
相关文章
poj 1185 炮兵阵地 (状态压缩dp)
如果你是刚刚开始做状态压缩dp,我建议你先看看 poj 3254 Corn Fields 这是一道比这一题更简单,更容易入门的题目。 还有在代码中我用了一个很巧妙的方法求一个数二进制数中1的个数 具体请看我博客中 x& (x - 1)==0 这篇文章 链接 。
53 1
POJ-2253,Frogger(最短路问题)
POJ-2253,Frogger(最短路问题)
poj supermaket (贪心)
http://poj.org/problem?id=1456 #include #include #include using namespace std; struct nod { int a; int d; }; bool cmp(nod x,nod y) { return x.
707 0
POJ 2370 Democracy in danger(简单贪心)
Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 2508 Description In one of the...
966 0
POJ3468&#160;线段树-模板题
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations.
612 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等