【TOJ 3282】 Rain's Array
来源:互联网 发布:黑咔相机软件 编辑:程序博客网 时间:2024/04/27 22:53
题意: 给定一个数组,每次取出相邻的两个数,左减右后放回原处,问是否可以组成所要的数。
看别人的代码都很短,我是把从后往前每个位置的可能都算出来,写得好挫
#include<iostream>#include<cstring>#include<vector>#include<algorithm>using namespace std;vector<long long> now;vector<long long> temp;long long a[30];int main(){ int t;int n;long long m; cin>>t; while(t--) { cin>>n>>m; for(int i=0;i<n;i++) cin>>a[i]; now.clear();temp.clear(); int nsum=0; nsum=a[n-2]+a[n-1]; now.push_back(a[n-2]-a[n-1]); for(int i=n-3;i>=0;i--) { temp=now; now.clear(); temp.push_back(nsum); nsum+=a[i]; for(int j=0;j<temp.size();j++) { now.push_back(a[i]-temp[j]); now.push_back(a[i]+temp[j]); } } bool flag=0; for(int i=0;i<now.size();i++) { if(now[i]==m) { flag=1;break; } } if(flag) cout<<"Yes"<<endl; else cout<<"No"<<endl; }}
0 0
- 【TOJ 3282】 Rain's Array
- RAIN && Disk Array
- LeetCode[Array]: Trapping Rain Water
- Trapping Rain Water Array+技巧
- TOJ 1171. Goldbach's Conjecture
- toj 2190 Nuanran's Idol
- TOJ 4116 GCD's magic
- TOJ 4109 Cyuunibyou's problem
- TOJ 1410.Euclid's Game
- TOJ 1859.Goldbach's Conjecture
- TOJ : 4065. Query on an array
- [week 4][leetcode][array] Trapping Rain Water
- leetcode.array--42. Trapping Rain Water
- TOJ 4127. God Le's Tree
- 【贪心】 TOJ 4121. Muxiaokui's Problem
- TOJ 2084.Biker's Trip Odometer
- TOJ 3778.Sheldon's Friendship II
- TOJ 3772.Rupxup's Math Problem
- const对象,NULL和nullptr,C++中创建对象数组
- 投放速度也会高低杠活动火热璟都国际地方
- Runtime.getRuntime().maxMemory()/freeMemory()/totalMemory()
- 动态规划
- 关于单元格编辑模式的几个小BUG
- 【TOJ 3282】 Rain's Array
- 字符串循环右移
- ZOJ-3706
- 关于Spring事务中的java.lang.ClassCastException $Proxy0 cannot be cast to
- QT之信号和槽
- poj 2274 The Race(逆序数+线段树)
- [程序员入行必备]CSS样式之优先级
- jqGrid源码分析(一)
- boost中使用线程池threadpool