博客
关于我
算法擂台微积分习题问题解答
阅读量:142 次
发布时间:2019-02-27

本文共 1450 字,大约阅读时间需要 4 分钟。

??????n????S?????????????????????????a_i?b_i???????????????????????????

????

  • ?????????????????x_i??????????x? + x? + ? + x_n = S?????a_i ? x_i ? b_i?
  • ?????????????dp???dp[i][j]???i???j???????
  • ????dp[0][0] = 1????0??0????????
  • ??????????i??????x_i????dp???????????????j?dp[i][j + x_i] += dp[i-1][j]?
  • ???????????????????????????
  • ????

    #include 
    #include
    #include
    using namespace std;int main() { int n, S; cin >> n >> S; vector
    a(n), b(n); for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; } vector
    dp(S + 1, 0); dp[0] = 1; for (int i = 0; i < n; ++i) { int min_sum = 0, max_sum = 0; for (int j = 0; j <= S; ++j) { if (dp[j] > 0) { min_sum = min(min_sum, j + a[i]); max_sum = max(max_sum, j + b[i]); } } if (max_sum > S) max_sum = S; if (min_sum > S) { dp = vector
    (S + 1, 0); break; } for (int j = max(0, S - max_sum); j <= S; ++j) { int current = j; for (int k = a[i]; k <= b[i]; ++k) { if (current - k >= 0 && dp[current - k] > 0) { dp[current] += dp[current - k]; } } } } cout << dp[S] << endl; return 0;}

    ????

  • ?????????n????S????????a_i?b_i?
  • ??????????dp?????i???j??????????dp[0] = 1?
  • ???????????i?????????x_i??????dp???
  • ?????????j???????????
  • ?????????dp[S]????S???????
  • ???????????????????????????????????????????

    转载地址:http://vdgf.baihongyu.com/

    你可能感兴趣的文章
    OSChina 周五乱弹 ——吹牛扯淡的耽误你们学习进步了
    查看>>
    SQL--mysql索引
    查看>>
    OSChina 周四乱弹 ——程序员为啥要买苹果手机啊?
    查看>>
    OSChina 周日乱弹 —— 2014 年各种奇葩评论集合
    查看>>
    OSChina 技术周刊第十期,每周技术抢先看!
    查看>>
    OSError: no library called “cairo-2“ was foundno library called “cairo“ was foundno library called
    查看>>
    OSError: [WinError 193] %1 不是有效的 Win32 应用程序。
    查看>>
    osgearth介绍
    查看>>
    OSGi与Maven、Eclipse PlugIn的区别
    查看>>
    Osgi环境配置
    查看>>
    OSG——选取和拖拽
    查看>>
    OSG中找到特定节点的方法(转)
    查看>>
    OSG学习:C#调用非托管C++方法——C++/CLI
    查看>>
    OSG学习:OSG组成(三)——组成模块(续):OSG核心库中的一些类和方法
    查看>>
    OSG学习:OSG组成(二)——渲染状态和纹理映射
    查看>>
    OSG学习:WIN10系统下OSG+VS2017编译及运行
    查看>>
    OSG学习:人机交互——普通键盘事件:着火的飞机
    查看>>
    OSG学习:几何体的操作(一)——交互事件、简化几何体
    查看>>
    OSG学习:几何体的操作(二)——交互事件、Delaunay三角网绘制
    查看>>
    OSG学习:几何对象的绘制(一)——四边形
    查看>>