博客
关于我
算法擂台微积分习题问题解答
阅读量: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/

    你可能感兴趣的文章
    order by rand()
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement profile
    查看>>
    org.apache.commons.beanutils.BasicDynaBean cannot be cast to ...
    查看>>
    org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: not s
    查看>>
    sqlserver学习笔记(三)—— 为数据库添加新的用户
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    SQL-CLR 类型映射 (LINQ to SQL)
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
    查看>>
    org.tinygroup.serviceprocessor-服务处理器
    查看>>
    org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
    查看>>