当前位置:网站首页>Shredding Company poj 1416
Shredding Company poj 1416
2022-06-26 00:03:00 【AMjieker】
Shredding Company
Their thinking : Violent search dfs
Use two strings to store the target and cut string
utilizestlOfstringOfsubstrInterceptkTolThen convert it into numbers and fill in avectorArray , Each of the enumerated schemes is stored inmap<int,vector< int> >in By the wayansandansfansfRepresents the number of repetitions
Code :
#include<iostream>
#include<map>
#include<vector>
#define int long long
using namespace std;
string a,b;
int ai,bi;
int ans,ansf;
map<int,vector<int> > mp;
vector<int> d;
inline int toint(string s){
int tt(0);
for(int i=0;i<s.size();i++) tt=tt*10+s[i]-'0';
return tt;
}
void dfs(int k,int v){
if(v>ai) return;
if(k==b.size()){
if(ans<v){
ans = v,ansf = 0;
for(int i=0;i<d.size();i++)
mp[ans].push_back(d[i]);
}else if(ans==v){
ansf++;
}
return;
}
int i(1);
while(k+i<=b.size()){
int t = toint(b.substr(k,i));
if(t+v>ai) break;
d.push_back(t);
dfs(k+i,t+v);
d.pop_back();
i++;
}
}
signed main(){
while(cin>>a>>b&&a!="0"&&b!="0"){
ai = toint(a);
bi = toint(b);
if(ai==bi) {
cout<<a<<" "<<b<<endl;
// }else if(ai>bi){
// cout<<"error"<<endl;
}else{
d.clear();
mp.clear();
ans = 0;
ansf = 0;
dfs(0,0);
if(ansf){
cout<<"rejected"<<endl;
}else if(ans!=0){
cout<<ans;
for(int i=0;i<mp[ans].size();i++){
cout<<" "<<mp[ans][i];
}
cout<<endl;
}else{
cout<<"error"<<endl;
}
}
}
return 0;
}
边栏推荐
- Raspberry pie sends hotspot for remote login
- Static keyword explanation
- 社交网络可视化第三方库igraph的安装
- 《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
- static关键字详解
- mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动
- Object array de duplication
- Number array de duplication in JS
- Use Baidu map API to set an overlay (infowindow) in the map to customize the window content
- Two ways to center block level elements
猜你喜欢

Use Baidu map API to set an overlay (infowindow) in the map to customize the window content

Summary of c++ references and pointers

WINCC与STEP7的仿真连接_过路老熊_新浪博客

How to configure SQL Server 2008 Manager_ Old bear passing by_ Sina blog

如何配置SQL Server 2008管理器_过路老熊_新浪博客

keil编译运行错误,缺少error:#5:#includecore_cm3.h_过路老熊_新浪博客

《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)

手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客

文献调研(三):数据驱动的建筑能耗预测模型综述
![[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)](/img/d9/935bad29005e5846dc514c966e3b0e.png)
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)
随机推荐
InputStream流已经关闭了,但是依旧无法delete文件或者文件夹,提示被JVM占用等
WINCC与STEP7的仿真连接_过路老熊_新浪博客
The role of iomanip header file in actual combat
Object array de duplication
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
剑指 Offer 48. 最长不含重复字符的子字符串
Common knowledge points in JS
P3052 [USACO12MAR]Cows in a Skyscraper G
Talk about the copy on write mechanism of PHP variables or parameters
JS中的数字数组去重
猕猴桃酵素的功效_过路老熊_新浪博客
虚析构和纯虚析构及C ++实现
IDEA常用快捷键
Given the parameter n, there will be n integers 1, 2, 3,... From 1 to n, n. These n arrays have n! An arrangement that lists all columns in ascending order of size and marks them one by one. Given n a
Two ways to center block level elements
网络协议之:redis protocol详解
Circuit de fabrication manuelle d'un port série de niveau USB à TTL pour PL - 2303hx Old bear passing Sina blog
keil编译运行错误,缺少error:#5:#includecore_cm3.h_过路老熊_新浪博客
给定参数n,从1到n会有n个整数1,2,3,...,n,这n个数组共有n!种排列,按照大小顺序升序排列出所有列的情况,并一一标记,给定n和k,返回第k个值
Backup restore of xtrabackup