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. 安装lsb_release

    lsb_release命令用来查看当前系统的发行版信息(prints certain LSB (Linux Standard Base) and Distribution information.). ...

  2. Ubuntu 搭建svn服务器 ,以及常见错误解决方案

    一.安装命令: 1)以root身份登录.执行:sudo su -命令 2)执行安装命令:apt-get install subversion   二.创建项目目录 1)mkdir  /home/svn ...

  3. Vue 嵌套数组 数组更新视图不更新

    关于Vue的响应式原理,可以看官方文档或其他资料, https://www.jianshu.com/p/34de360d6035 data里定义了一个数组arr,数组的元素可以是同样格式的数组arrC ...

  4. Intellij IDEA 2017 控制台打印换行

    Intellij IDEA 2017 控制台打印的内容超过屏幕宽度了,请问怎么自动换行? 记得重启idea

  5. sklearn_k邻近分类_KNeighborsClassifier

    # coding:utf-8 import numpy as np import matplotlib.pyplot as plt from sklearn.neighbors import KNei ...

  6. Ubuntu 设置 sudo 开机自启动项 无需输入密码

    如果你想设置一个需要sudo权限执行的开机自启动项,而不需要输入密码,那么你需要把该程序加入  /etc/sudoers 中.要直线这个, 首先执行 sudo visudo ,在文件最后加入下面一行 ...

  7. Java NIO之拥抱Path和Files

    Java面试通关手册(Java学习指南)github地址(欢迎star和pull):https://github.com/Snailclimb/Java_Guide 历史回顾: Java NIO 概览 ...

  8. popular short sentences

    backward compatibility 向后兼容 archive 文档

  9. Add Two Numbers I & II

    Add Two Numbers I You have two numbers represented by a linked list, where each node contains a sing ...

  10. MySQL 5.7半同步复制after sync和after commit详解【转】

    如果你的生产库开启了半同步复制,那么对数据的一致性会要求较高,但在MySQL5.5/5.6里,会存在数据不一致的风险.有这么一个场景,客户端提交了一个事务,master把binlog发送给slave, ...