题意:https://nanti.jisuanke.com/t/41420

给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值。

思路:

从最大重量的石子开始背包,每次ans+=dp【j-v【i】】就行了。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int v[N],dp[N];
void Init(int _[],int n)
{
for(int i=;i<=n;++i)
_[i]=;
} void PR(int _[],int n)
{
for(int i=;i<=n;++i)
pr("%d ",_[i]);
pr("\n");
} bool J(int sum,int x,int min_)
{
return *x>=sum&&*x<=sum+min_;
} int main()
{
int T;
sc("%d",&T);
while(T--)
{
int n,sum=;
sc("%d",&n);
for(int i=;i<=n;++i)
sc("%d",&v[i]),sum+=v[i];
sort(v+,v++n);
Init(dp,sum); ll ans=;
dp[]=;
for(int i=n;i>=;--i)
{
for(int j=sum;j>=v[i];--j)
if(dp[j-v[i]])
{
dp[j]+=dp[j-v[i]];
dp[j]%=mod;
ans+=J(sum,j,v[i])?dp[j-v[i]]:;
ans%=mod;
}
}
pr("%lld\n",ans);
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019的更多相关文章

  1. The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game

    题目:https://nanti.jisuanke.com/t/41420 思路:当a(a∈S′)为最小值 如果Sum(S′)−a≤Sum(S−S′)成立 那么(∀t∈S′,Sum(S′)−t≤Sum ...

  2. The Preliminary Contest for ICPC Asia Xuzhou 2019 【 题目:so easy】{并查集维护一个数的下一个没有被删掉的数} 补题ING

    题意:给[1,n],n个数,有两种操作: 1 x,删去x2 x,查询还未被删去的数中大于等于x的最小的数是多少. input: output: 做法:按照并查集的方法压缩路径 代码: #include ...

  3. The Preliminary Contest for ICPC Asia Shenyang 2019 C Dawn-K's water (完全背包)

    完全背包为什么要取到M,可以取到2*M嘛,这题需要整取,对于不能整取的背包容量,dp[k]=INF,以及dp[j-water[i].weight]=INF时,dp[j]也不需要更新.如果不整取的话,后 ...

  4. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center

    You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...

  5. 洛谷 P1064 金明的预算方案【DP/01背包-方案数】

    题目背景 uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家--餐馆,很低端的那种. uim指着墙上的价目表(太低级了没有菜单),说:"随便点". 题目描述 不过ui ...

  6. caioj 1412 动态规划3:a+b问题(完全背包方案数)

    每个素数就是一个物品,然后就相当于求完全背包方案数 把max改成+就好了. #include<cstdio> #include<vector> #include<cstr ...

  7. HDU 1284 钱币兑换问题 (动态规划 背包方案数)

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. UVa 11137 (完全背包方案数) Ingenuous Cubrency

    题意:用13.23……k3这些数加起来组成n,输出总方案数 d(i, j)表示前i个数构成j的方案数则有 d(i, j) = d(i-1, j) + d(i, j - i3) 可以像01背包那样用滚动 ...

  9. Buy the souvenirs---hdu2126(01背包输出方案数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2126 有n个物品每个物品的价格是v[i],现在有m元钱问最多买多少种物品,并求出有多少种选择方法: 如 ...

随机推荐

  1. Python 通过文件名批量移动文件

    Python 通过文件名批量移动文件 https://stackoverflow.com/questions/28913088/moving-files-with-wildcards-in-pytho ...

  2. vue中用watch监听当前路由

    之前做项目时,特别是后台项目,左边都有侧边栏,我们需要做到点击某个侧边栏的项让这个项高亮,之前采用的是给每个项绑定一个值,点击某个项时,就将这个值付给一个变量,在每一项上判断这个变量是否与每项上的值相 ...

  3. 二、编译安装LAMP之httpd-2.4.4

    回顾 PHP:脚本编程语言,php解释器 Webapp:面向对象的特性 Zend: 第一段:词法分析.句法分析.编译为Opcode: opcode放置于内存中 第二段:执行opcode: opcode ...

  4. Android学习_MVC与Adapter

    一.           MVC模式 MVC模式代表Model-View-Controller(模型-视图-控制器)模式.这种模式用于应用程序的分层开发. Model(模型):代表一个存取数据的对象或 ...

  5. 如何简单的在linux上安装jdk并配置环境变量

    这篇文章是为了给我一会自己安装的时候方便使用的,所以内容很简单,平时在wendows系统上安装很容易,但是换到linux系统上面就蒙圈了. 一.下载jdk文件 我这提供的是官方的地址:http://w ...

  6. Java中可变参数

    从java5开始出现了可变参数,这是对java方法及数组的拓展! 方法中可以接受的参数不再是固定个数的,而是随着具体需求传递的多少来决定. 定义格式: 返回值类型  方法名(参数类型 ... 形式参数 ...

  7. JsonObject处理时间转换问题

    正常传时间的时候使用JsonObject转换的时候会把整个日期都转换成一个新的对象,而如何转换成传统的yyyy-MM-dd HH:mm:ss类型呢 常用的时间格式 private String for ...

  8. [Java]用 MessageFormat 拼接组合字符串

    package com.hy; import java.text.MessageFormat; public class Test3 { public static void main(String[ ...

  9. LC 813. Largest Sum of Averages

    We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the su ...

  10. Android : 高通平台的HVX简介及调试

    一.HVX简介 HVX(“Hexagon矢量扩展”,Hexagon-六边形.Vector-矢量.Extensions-扩展)是Hexagon 680 DSP的典型特性,能够在执行图像处理应用中的计算负 ...