Codeforces Round #437 (Div. 2) B 865A Save the problem! (思维)

41 篇文章 0 订阅
24 篇文章 0 订阅

这题感觉很棒啊.
想了蛮久的.
事实上跟多重背包没什么关系,似乎只要1,2两个数,就可以构造出所有种类数量.

/*  xzppp  */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int MAXM = 2e3+17;
const int MAXV = 2*1e3+17;
const int BIT = 15+3;
const int INF = 0x7fffffff;
const LL INFF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAXN = 1e6+17;
int a[10+17] = {1,2,3,4,5,6,7,8,9,10};
int dp[MAXN];
int main()
{
    #ifndef ONLINE_JUDGE 
    FFF
    #endif
    int n;
    cin>>n;
    dp[0] = 1;
    for (int i = 0; i < 10; ++i)
    {
        bool can = false;
        int zt;
        for (int j = 0; j <= 1e6 ; ++j)
        {
            if(j>=a[i])
                dp[j] += dp[j-a[i]];
            if(dp[j]==n)
            {
                zt = j;
                can = true;
            }
        }
        if(can)
        {
            cout<<zt<<endl;
            cout<<i+1<<endl;
            for (int j = 0; j <= i; ++j)
            {
                cout<<j+1<<endl;
            }
            break;
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值