Tanks

最关键的一点就是怎么判方案是否存在。。 只要存在若干个坦克之和的sum % k == v % k 就有解, 否则无解。

我怎么想不到呢。。。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned 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 ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);using namespace std;const int N = 5000 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
const double PI = acos(-1);template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}int n, k, v, sum, now1, now2, a[N];
bool dp[N][N];
bool f[N][N];
vector<int> vc[2];int main() {scanf("%d%d%d", &n, &k, &v);for(int i = 1; i <= n; i++) {scanf("%d", &a[i]);sum += a[i];}if(sum < v) return puts("NO"), 0;dp[0][0] = true;for(int i = 0; i < n; i++) {for(int j = 0; j < k; j++) {if(!dp[i][j]) continue;dp[i + 1][(j + a[i + 1]) % k] = true;f[i + 1][(j + a[i + 1]) % k] = true;dp[i + 1][j] = true;f[i + 1][j] = false;}}if(!dp[n][v % k]) return puts("NO"), 0;int tmp = v % k;for(int i = n; i >= 1; i--) {if(f[i][tmp]) {vc[0].push_back(i);tmp = ((tmp - a[i]) % k + k) % k;} else {vc[1].push_back(i);}}sort(ALL(vc[0]));sort(ALL(vc[1]));for(auto& t : vc[0]) now1 += a[t];now2 = sum - now1;puts("YES");for(int i = 1; i < SZ(vc[0]); i++) printf("100000 %d %d\n", vc[0][i], vc[0][0]);for(int i = 1; i < SZ(vc[1]); i++) printf("100000 %d %d\n", vc[1][i], vc[1][0]);if(!SZ(vc[1])) vc[1].push_back(vc[0].back());if(!SZ(vc[0])) vc[0].push_back(vc[1].back());if(now1 < v) printf("%d %d %d\n", (v - now1) / k, vc[1][0], vc[0][0]);if(now1 > v) printf("%d %d %d\n", (now1 - v) / k, vc[0][0], vc[1][0]);return 0;
}/*
*/

转载于:https://www.cnblogs.com/CJLHY/p/10821693.html

Codeforces 920D Tanks (看题解)相关推荐

  1. codeforces div2 Not Assigning 题解

    codeforces div2 Not Assigning 题解 原题链接 /* 题意:构造一棵素数树.素数树定义如下: 这颗树中任意一条边 or 任意两条边 权重之和为素数,每条边的权重自己分配. ...

  2. Codeforces 773D Perishable Roads 最短路 (看题解)

    Perishable Roads 智商题, 不会啊.. 贴个官方题解 https://codeforces.com/blog/entry/51883 #include<bits/stdc++.h ...

  3. Codeforces 1089D Eels (看题解)

    Eels 感觉想不出来这种东西.. 题解讲的很清楚啦. 我好lj啊. https://codeforces.com/blog/entry/64331 #include<bits/stdc++.h ...

  4. Codeforces 1155F Delivery Oligopoly dp(看题解)

    看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...

  5. Codeforces 868F Yet Another Minimization Problem 决策单调性 (看题解)

    Yet Another Minimization Problem dp方程我们很容易能得出, f[ i ] = min(g[ j ] + w( j + 1, i )). 然后感觉就根本不能优化. 然后 ...

  6. Codeforces 924D Contact ATC (看题解)

    Contact ATC 我跑去列方程, 然后就gg了... 我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ], 对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件. ...

  7. Codeforces 671C Ultimate Weirdness of an Array 线段树 (看题解)

    Ultimate Weirdness of an Array 写不出来, 日常好菜啊.. 考虑枚举GCD, 算出一共有多少个对 f(l, r) <= GCD, 我们用fuc[ i ] 表示的是在 ...

  8. Codeforces 827D Best Edge Weight 倍增 + 并查集 || 倍增 + 压倍增标记 (看题解)

    Best Edge Weight 我们先找出一棵最小生成树, 对于非树边来说, 答案就是两点路径上的最大值 - 1, 这个直接倍增就能处理. 对于树边来说, 就是非树边的路径经过这条边的最小值 - 1 ...

  9. Codeforces 494D Birthday 树形dp (看题解)

    Birthday 没想到平方和能在树上dp出来的... 知道了如何转移, 那么就很好写了... #include<bits/stdc++.h> #define LL long long # ...

最新文章

  1. 自学python爬虫要多久-Python爬虫要学多久,给初学编程者的建议
  2. 2.STM32中对Key_GPIO_Config()函数的理解(自定义)之轮询控制按键LED
  3. Java实现基数排序及其推导过程 Radix Sort
  4. NSNotification、delegate和KVO的区别
  5. Greg and Array CodeForces - 296C(差分数组+线段树)
  6. matlab 定义一个有自变量的方程_Eviews、Stata、Python、Matlab、R描述+相关+回归分析教程汇总...
  7. IIS上部署Net.Core
  8. docker:轻量级图形页面管理工具Portainer
  9. DISC免费性格测试题
  10. 通过规模化Scrum创造最新技术的打印机
  11. Android binder
  12. matlab 上三角矩阵变为对称矩阵,已知上/下三角矩阵如何快速将对称阵补全
  13. Win10在Dev-C++配置Npcap
  14. SQLAlchemy学习-1.环境准备与基础使用
  15. 0xC000041D:用户回调期间遇到未经处理的异常
  16. kdj买卖指标公式源码_通达信一品KDJ波段买卖操作源码免费指标公式
  17. Python入门教程三:显示'Welcome to Python'五次
  18. ArcEingine——IRelationalOperator的Crosses与Overlaps
  19. 阿里P7被裁员,找工作小半年了,流程走着走着就没了
  20. 追踪算法MUSTer体验

热门文章

  1. PCM转MP3工具的封装
  2. On Perseverance
  3. Python(2.7.6) 列表推导式
  4. MySQL-查询结果缓存
  5. 提高代码改造过程的小想法
  6. Android的沉浸式状态栏与变色状态栏详解
  7. 6个值得推荐的Android开源框架简介
  8. Redis主从复制下的工作原理
  9. 同一台服务器上面安装多个mysql数据库
  10. mysql event 学习