当前位置:网站首页>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;
}
边栏推荐
- 用frp搭建云电脑
- 树莓派开机发送热点进行远程登录
- Stream in PHP socket communication_ Understanding of select method
- Compiling protobuf protocol files using makefile in PHP
- InputStream流已经关闭了,但是依旧无法delete文件或者文件夹,提示被JVM占用等
- oracle写一个先插入一条数据,在将该数据中一个字段更新的触发器的坑
- Summary of c++ references and pointers
- Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
- Connecting MySQL database with VBScript_ Old bear passing by_ Sina blog
- sqlServer2008中float类型数据与datetime类型数据互转
猜你喜欢

Connecting MySQL database with VBScript_ Old bear passing by_ Sina blog

Reading notes on how to connect the network - hubs, routers and routers (III)

Final and static

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

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or

文献调研(二):基于短期能源预测的建筑节能性能定量评估

postman如何测试需要登录的接口

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

STEP7主站与远程I/O组网_过路老熊_新浪博客

MySQL version upgrade + data migration
随机推荐
Common methods of object class
php进程间传递文件描述符
Prototype chain test questions in JS --foo and getname
final和static
树莓派开机发送热点进行远程登录
关于运行scrapy项目时提示 ModuleNotFoundError: No module named 'pymongo‘的解决方案
php中使用Makefile编译protobuf协议文件
[转载]RSLOGIX 5000实例教程
One article explains R & D efficiency! Your concerns are
Analyse des cinq causes profondes de l'échec du développement de produits
使用npm创建并发布包时遇到的常见问题
对伪类的理解
IDEA中如何生成get/set方法
Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog
SSM integrated learning notes (mainly ideas)
Use Baidu map API to set an overlay (infowindow) in the map to customize the window content
Transformation of communication protocol between Siemens S7-200PLC and Danfoss inverter_ Old bear passing by_ Sina blog
Keil compilation run error, missing error: # 5: # includecore_ cm3.h_ Old bear passing by_ Sina blog
DNS复习
关于二分和双指针的使用