东华复试OJ二刷复盘14

进阶20:给出一个整数 n(n<10^30) 和 k 个变换规则规则:一位数可变换成另一个一位数,变换得到的数不能为零。仅要求输出经过任意次的变换产生出不同整数的个数。

例如:n=234。有规则(k=2):

2-> 5

3-> 6

上面的整数 234 经过变换后可能产生出的整数为(包括原数):

234

534

264

564

共 4 种不同的产生数

  • 经过测试,每一位数字的变化能经过多次变化规则。
  • DFS列出所有可能数字过于复杂且数据规模超过int的数量级。
    • 列出数字形式是考虑到形成不同的数字才能计数。实际上每一位取到不同的数字得到的结果都是不同的,不需要形成数字后进行比较是否重复。
  • 数据规模总次数超过int上限,用数组的大数乘和string接收字符串。
cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

vector<int> orgin;
vector<int> target;
vector<int> ans;
vector<int> FinAns;

void GetNum(vector<int>& UsedNum, int cur) {
    // 如果当前数字已经在 UsedNum 里,说明已经处理过,避免重复
    if (find(UsedNum.begin(), UsedNum.end(), cur) != UsedNum.end()) {
        return;
    }
    UsedNum.push_back(cur);
    // 尝试所有规则,看 cur 能变成什么
    for (int i = 0; i < orgin.size(); i++) {
        if (orgin[i] == cur) {
        	//对新变化的数检查是否存在新转化规则 
            GetNum(UsedNum, target[i]);
        }
    }
}

void DFS(vector<int> numbers,int index,vector<int> UsedNum){
	if(index==numbers.size()){
		return;
	}
	
	//得到该位能取到的全部数字 
	GetNum(UsedNum,numbers[index]);
	ans.push_back(UsedNum.size());

	vector<int> newUsedNum;
	DFS(numbers,index+1,newUsedNum);
	return;
}

void DaShuCheng(int index,int& jin){
	int num = ans[index];
	if(index==0){
		FinAns.push_back(num);
	}
	else{
		for(int i=0;i<FinAns.size();i++){
			FinAns[i]*=num;
			FinAns[i]+=jin;
			jin =  FinAns[i]/10;
			FinAns[i]%=10; 
		}
		if(jin){
			FinAns.push_back(jin);
			jin=0;
		}
	}
}


int main(){
	string num;
	int len;
	cin>>num>>len;
	vector<int> numbers;
	for(int i=0;i<num.size();i++){
		numbers.push_back(num[i] - '0');
	}

	for(int i=0;i<len;i++){
		int map1,map2;
		cin>>map1>>map2;
		orgin.push_back(map1);
		target.push_back(map2);
	}
	vector<int> UsedNum;//记录index对应数字的变化形式 
	DFS(numbers,0,UsedNum);
	int jin=0;
	for(int i=0;i<ans.size();i++){
		DaShuCheng(i,jin);
	}
	reverse(FinAns.begin(),FinAns.end());
	for(int i=0;i<FinAns.size();i++){
		cout<<FinAns[i];
	}

	system("pause");
}

进阶21:将念头从1到n编号,念头i来源于念头from[i],保证from[i]<i,from[i]=0表示该念头没有来源念头,只是脑袋一抽,灵光一现。输出共一行,一个正整数L表示最长的念头因果链中的念头数量

样例输入

8

0

1

0

3

2

4

2

4

样例输出

3

样例说明

最长的因果链有:

1->2->5 (from[5]=2,from[2]=1,from[1]=0)

1->2->7 (from[7]=2,from[2]=1,from[1]=0)

3->4->6 (from[6]=4,from[4]=3,from[3]=0)

3->4->8 (from[8]=4,from[4]=3,from[3]=0)

  • 错误1:越界异常,产生死循环了,错误在于来源是编号1~n,而对应下标为1-1~n-1。将TraceBack(LianChang,newindex,from);改为TraceBack(LianChang,newindex-1,from);
cpp 复制代码
#include <bits/stdc++.h>
using namespace std;


void TraceBack(int &LianChang,int index,vector<int>&from){
	LianChang++;
	if(from[index]==0){
		return ;
	}
	else{
		int newindex = from[index];
		TraceBack(LianChang,newindex-1,from);
	}	
}

int main(){
	int len;cin>>len;
	vector<int> from(len);
	for(int i=0;i<len;i++){
		cin>>from[i];
	}
	int LianChang=0;
	int ans=0;
	for(int i=0;i<len;i++){
		LianChang=0;
		TraceBack(LianChang,i,from);
		ans = max(ans,LianChang);
	}
	cout<<ans<<endl;
	system("pause");
} 

In recent years, pre-trained models have played an important role in artificial intelligence research. Researchers typically first train a general model using large-scale datasets and then fine-tune it on specific tasks. In this way, the model can utilize the knowledge learned during the pre-training stage to improve the performance of downstream tasks. For example, in the field of natural language processing, many language models are pre-trained on massive text corpora and achieve excellent results in tasks such as text classification, machine translation, and question answering. The pre-training and fine-tuning framework not only reduces training costs but also improves the generalization ability of models. Therefore, this approach has become an important paradigm in modern artificial intelligence research.

  • 近年来,预训练模型在人工智能研究中扮演了重要的角色。研究员普遍地使用大规模数据集来先训练一个普遍的模型再在特定任务中调优。在这种方式里,模型能在预训练阶段利用学习到的知识来改善下游任务中的表现。比如,在自然语言处理领域中,许多语言模型再大量的文本语料库中预训练并在一些任务中取得了极好的结果,比如文本分类、机器翻译和回答问题。预训练和微调架构不仅减少了训练成本,还提高了模型的泛化能力。从而,这一方法在现代化的人工智能研究中成为了一个重要范例。
  • downstream tasks 下游任务、 fine-tuning 微调
相关推荐
炽烈小老头1 小时前
【每天学习一点算法 2026/03/20】单词搜索
学习·算法
xiaoxiaoxiaolll1 小时前
最新《Nature Communications》:多元素共生策略为金属材料穿上“抗疲劳铠甲”
学习
元契2 小时前
英语基础语法学习0
学习
arvin_xiaoting2 小时前
OpenClaw学习总结_I_核心架构系列_Gateway架构详解
学习·架构·llm·gateway·ai-agent·飞书机器人·openclaw
421!2 小时前
ESP32学习笔记之UART
笔记·学习·嵌入式·esp32·通信
蓝桉~MLGT2 小时前
Ai-Agent学习历程(插播内容)—— 基于现在最新的Skills、MCP、Rules等进行详细拆解,并列举出使用场景
人工智能·学习
知识分享小能手2 小时前
Redis入门学习教程,从入门到精通,Redis进阶编程知识点详解(5)
数据库·redis·学习
夏日听雨眠2 小时前
Linux学习1
linux·服务器·学习
朗迹 - 张伟2 小时前
UE5 C++学习笔记
c++·学习·ue5