B - Enlarging Enthusiasm

感觉做到过好多的dp题都会和单调性结合在一起。

思路:dp[ s ][ pre ][ res ] 表示的是已选择了s,上一个是pre, 还有res 的分数的方案数。

然后再枚举下一个位置的时候,把其他位置的也减去这个值,因为是单调递增的所以不会多减,

这样就能保证pre 和 当前要枚举的 i 位置的差值永远为 a[ pre ] - a[ i ]

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m, ans, mx, a[], dp[<<][][], num[<<]; int dfs(int s, int pre, int res) {
if(res < ) return ;
if(s+ == <<n) return ;
if(~dp[s][pre][res]) return dp[s][pre][res];
dp[s][pre][res] = ;
for(int i = ; i < n; i++)
if(!(s>>i&)) dp[s][pre][res] += dfs(s|<<i, i, res-max(a[pre]-a[i]+, )*(n-num[s]));
return dp[s][pre][res];
}
int main() {
memset(dp, -, sizeof(dp));
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++) {
scanf("%d", &a[i]);
mx = max(mx, a[i]);
}
for(int i = ; i < (<<n); i++)
num[i] = num[i-(i&-i)] + ;
for(int i = ; i < n; i++)
if(a[i] != mx) ans += dfs(<<i, i, m-(mx-a[i]+)*n);
printf("%d\n", ans);
return ;
} /*
*/

2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) B - Enlarging Enthusiasm dp好题的更多相关文章

  1. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) 思路: A Exam 思路:水题 代码: #include<bits ...

  2. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  3. Contest Setting 2018 ICPC Pacific Northwest Regional Contest dp

    题目:https://vj.69fa.cn/12703be72f729288b4cced17e2501850?v=1552995458 dp这个题目网上说是dp+离散化这个题目要对这些数字先处理然后进 ...

  4. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...

  5. 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) S Surf

    SurfNow that you've come to Florida and taken up surng, you love it! Of course, you've realized that ...

  6. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) 题解

    [题目链接] A - Alphabet 最长公共子序列.保留最长公共子序列,剩余的删除或者补足即可. #include <bits/stdc++.h> using namespace st ...

  7. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Exam Solved. 温暖的签. #include<bits/stdc++.h> using namespace std; ; int k; char str1[maxn], st ...

  8. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) K Tournament Wins

    题目链接:http://codeforces.com/gym/101201 /* * @Author: lyucheng * @Date: 2017-10-22 14:38:52 * @Last Mo ...

  9. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    A. Odd Palindrome 所有回文子串长度都是奇数等价于不存在长度为$2$的偶回文子串,即相邻两个字符都不同. #include<cstdio> #include<cstr ...

随机推荐

  1. why inline functions must be put in header files?

    [why inline functions must be put in header files?] 编译中有2个过程:compile.link.先进行compile,compile中把源代码编译成 ...

  2. bzoj1190 [HNOI2007]梦幻岛宝珠

    传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1190 [题解] 首先,我们把所有物品都分解成$a\times 2^b$的形式,然后把物品按 ...

  3. getElementById()方法取值

    举例子: javascript: var time = document.getElementById('jidu').value; //指定时间 var taskclass = document.g ...

  4. js模拟自动点击事件

    1.直接上代码很直观 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  5. 新电脑重新安装win10+python3.6+anaconda+tensorflow1.12(gpu版)

    安装了一天的软件,遇到了很多坑,在快泪崩的时候,始终以磨刀不误砍柴工鼓励自己,坚持安好了,话不多说,上干货: 前言:        TensorFlow 有两个版本:CPU 版本和 GPU 版本.GP ...

  6. 2016.6.19——Length of Last Word

    Length of Last Word 本题收获: 1.str.size()为负 2.size_t引发的死循环 3.题目思路,有时在写代码时很不清楚边界条件的输出值是什么,若为面试,一定要问清楚. 题 ...

  7. python 爬虫简单的demo

    ''' @author :Eric-chen @contact:809512722@qq.com @time :2018/1/3 17:55 @desc :通过爬取http://movie.douba ...

  8. container_of分析【转】

    转自:http://blog.csdn.net/tigerjibo/article/details/8299589 1.container_of宏 1> Container_of在Linux内核 ...

  9. MsSqlserver 查看锁表与解锁

    查看被锁表: select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys. ...

  10. Flask--wtforms快速使用和表单验证(附示例)

    一.Form类 表单提供WTForms中最高级别的API.它们包含您的字段定义,委托验证,获取输入,聚合错误,并且通常用作将所有内容组合在一起的粘合剂. class wtforms.form.Form ...