东华复试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来源于念头fromi,保证fromi<i,fromi=0表示该念头没有来源念头,只是脑袋一抽,灵光一现。输出共一行,一个正整数L表示最长的念头因果链中的念头数量

样例输入

8

0

1

0

3

2

4

2

4

样例输出

3

样例说明

  最长的因果链有:

  1->2->5 (from5=2,from2=1,from1=0)

  1->2->7 (from7=2,from2=1,from1=0)

  3->4->6 (from6=4,from4=3,from3=0)

  3->4->8 (from8=4,from4=3,from3=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 微调
相关推荐
a11177610 小时前
2FA 验证码生成器(github登录验证 app)
笔记·学习
我的xiaodoujiao10 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest
你想知道什么?12 小时前
线性回归-学习笔记
笔记·学习·线性回归
鱼毓屿御12 小时前
从「只会聊」到「边想边做」的跃迁
前端·学习·react.js
AOwhisky13 小时前
Python 学习笔记(第十五期)——运维自动化(下·后篇):堡垒机实战——paramiko高阶篇
运维·python·学习·云原生·自动化·运维开发
minglie115 小时前
zynq中linux系统的自动登录和免密登录
学习
茯苓gao15 小时前
嵌入式开发笔记:Qt信号槽机制深度解析——从原理到实战的全方位指南
开发语言·笔记·嵌入式硬件·qt·学习
我想我不够好。16 小时前
监控学习 7.23 1.5hour
学习
泰勒朗斯18 小时前
Helicopter FBI-405尾电机版本设置
学习
minglie119 小时前
香橙派zero3配个iic屏显示ip
linux·学习