思路:叶子的标记只会发生在叶子,并且标记应该返到根的下一层才是最优的,如果其他分路又有标,那么直接否定 标的数量满足的话,小于等于1. 再考虑总和 或 删一个最大的代价(这个代价必然是根节点的下一层之中的点)。
先处理出根节点下一层的全部材料,并且把超过了1e9的标记。如果标记的个数cnt>=2,那么直接Impossible,否则如果cnt==1,再判是否ans>1e9. 否则如果cnt==0,ans-mx,再判ans>1e9?
思路是这么个思路,主要是实现要实现好。
- const int maxx=1e9;
- int n,k;
- vector<int> vct[100005];
- unordered_map<int,bool> typ;
- int getProduct(int need,int x){
- if(need>maxx) return 0;
- if(!typ[x]){
- int zz;
- need*vct[x][0]>maxx?zz=0:zz=need*vct[x][0];
- return zz;
- }
- int res=0;
- for(int i=1;i
size();i+=2){ - int cur=getProduct(need*vct[x][i-1],vct[x][i]); need*vct[x][i-1],累乘!
- if(cur==0) return 0;
- else res+=cur;
- if(res>maxx) return 0;
- }
- return res;
- }
- key:建一棵树
- 叶子的标记只会发生在叶子,并且标记应该返到根的下一层才是最优的,如果其他分路又有标,那么直接否定
- 标的数量满足的话,小于等于1. 再考虑总和 或 删一个最大的
- 关于 agKc 实在不喜欢自动化于是啥都自己合成这件事
- https://acm.hdu.edu.cn/contest/problem?cid=1130&pid=1009
- https://acm.hdu.edu.cn/showproblem.php?pid=7513
- void solve(){ 顶级模拟题..wa了22发才ac.
- cin>>n>>k;
- typ.clear();
- for(int i=1;i<=n;i++){
- vct[i].clear();
- int typ0; cin>>typ0;
- typ[i]=typ0;
- if(typ0){
- int zz; cin>>zz;
- for(int j=1;j<=2*zz;j++){
- int x; cin>>x;
- vct[i].emplace_back(x);
- }
- }
- else{
- int x; cin>>x;
- vct[i].emplace_back(x);
- }
- }
- vector<int> product;
- for(int i=1;i
size();i+=2) product.emplace_back(getProduct(vct[k][i-1],vct[k][i])); - int cnt=0,mx=0,sum=0;
- for(auto p:product){
- if(p==0) cnt++;
- mx=max(mx,p),sum+=p;
- }
- 最后这里要讨论好!!
- if(cnt>=2||cnt==1&&sum>maxx) cout<<"Impossible"<
- else if(cnt==0){
- sum-=mx; cnt==0才能减
- if(sum>maxx) cout<<"Impossible"<
- else cout<
- }
- else if(cnt==1) cout<
- }
-
相关阅读:
设计模式学习笔记 - 面向对象 - 1.面向对象到底讨论的是什么
新手如何去做性能测试?
【IDEA】idea恢复pom.xml文件显示灰色并带有删除线
既然有HTTP协议,为什么还要有RPC
网络支付安全:面临的风险与防范策略
.net 使用IL生成代理类实现AOP对比Java Spring Boot的AOP
【git 介绍】AhuntSun
python珍藏宝藏学习资料
mits6.081-lab2
用智能文字识别技术赋能古彝文数字化之路
-
原文地址:https://blog.csdn.net/qq_42643660/article/details/141093443