2019上海网络赛 J Stone game
2019-09-16 17:43
393 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_43449107/article/details/100895626
题意:分2堆石头,使得第一堆的总重量大于第二堆,并且去掉第一堆的任意一块,必有第一堆的重量小于等于第二堆,求分配方法的总数;
思路考虑将数组从大到小排序,然后01背包,dp[i]表示价值为i的分配方法的总数;
代码:
#include<bits/stdc++.h> #include<iostream> #include<cstdio> using namespace std; const int mod=1e9+7; bool cmp(int a, int b) { return a>b; } int dp[150005]; int a[305]; int main() { int T,n; scanf("%d", &T); while(T--) { scanf("%d", &n); int sum=0, ans=0; for(int i=0; i<n; i++) { scanf("%d", &a[i]); sum+=a[i]; } sort(a, a+n, cmp); memset(dp,0,sizeof(dp)); dp[0]=1; for(int i=0; i<n; i++) { for(int j=sum; j>=a[i]; j--) { if(j>=sum-j && j-a[i]<=sum-j) { ans=(ans+dp[j-a[i]])%mod; } dp[j]=(dp[j]+dp[j-a[i]])%mod; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- 2019上海网络赛 Light bulbs(离散化+差分)
- poj 1738 An old Stone Game(此题数小则可用区间DP,数较大用一维数组或者GarsiaWachs算法),待续
- 上海好的seo公司有哪些?清法网络值得信赖
- 7月28号的题目:Printer Queue&&Parencodings&&Grandpa is Famous&&Emag eht htiw Em Pleh&&An Old Stone Game
- HDU A simple stone game [K倍动态减法游戏]
- An old Stone Game ~~GarsiaWachs算法
- D - Game 2019省赛训练组队赛3.31周四-17fj
- POJ 3922 A simple stone game
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- 从RSA 2019看网络趋势
- A simple stone game (poj3922,博弈)
- HDU 1729 Stone Game
- 2019最新TCP/IP协议基础教程 网络协议基本功 共18课
- POJ1740 A New Stone Game (博弈)
- hdu 1729 Stone Game
- 【UVA1378】A Funny Stone Game (博弈-求SG值-输出方案)
- HDU 5044 Tree(LCA ,2014上海网络赛1003)
- [hdu 5051]2014上海网络赛 Fraction 数学 Benford's law/打表找规律
- 2019上海搜浪科技年会——“熔炼团队,开创未来”
- 2019最新崔庆才python3网络爬虫开发项目实战(完整)