当前位置: 首页 > news >正文

Pipeline Scheduling(UVA 690)

网址如下:

Pipeline Scheduling - UVA 690 - Virtual Judge (vjudge.net)

(第三方网站)

噫,好!我中了!

这题还是有点折磨的,刚开始我只会递归下一个程序运行的时间(范围在1~n),很明显,直接TLE,然后用C++STL里面的bitset容器来表示所有的程序运行状况(因为最差情况下最长的时间段是200,用longlong只有64位,不够表示),结果vjudge上直接表示Compile Error,应该是不能用

最后是上CSDN上去看其他人的解题思路:

http://t.csdnimg.cn/AxOel

其中,把时间段200缩短到20的方法启发了我,而且里面提到的jump数组也减少的了递归量

妙哉

按这个思路自己写了一下之后是AC了

代码如下:

#include<cstdio>
#include<cstring>
typedef long long LL;const int maxn = 20;LL unit[5];
int jump[maxn], cnt;//jump的个数
int n, ans;void init(void){memset(unit, 0, sizeof(unit));ans = n * 10; getchar(); cnt = 0;
}
void getjump(void){LL unit_t[5]; memcpy(unit_t, unit, sizeof(unit));for(int i = 1; i <= n; i++){bool is = true;for(int j = 0; j < 5; j++){unit_t[j] <<= 1;if(unit[j] & unit_t[j]) is = false;}if(is) jump[cnt++] = i;}
}
void dfs(LL state[5], int sum, int m){//剪枝if(sum + jump[0] * (10 - m) > ans) return;//尝试部署for(int i = 0; i < 5; i++) if(unit[i] & state[i]) return;//部署for(int i = 0; i < 5; i++) state[i] |= unit[i];//下一个if(m == 10) ans = sum;elsefor(int i = 0; i < cnt; i++){int val = jump[i];LL * p = new LL [5];for(int j = 0; j < 5; j++) p[j] = state[j] >> val;dfs(p, sum + val, m + 1);delete [] p;}
}int main(void)
{while(scanf("%d", &n) == 1 && n){//初始化init();//输入for(int i = 0; i < 5; i++){int tmp = 1; char c;for(int j = 0; j < n; j++, tmp <<= 1)if((c = getchar()) == 'X') unit[i] |= tmp;getchar();}//得出答案getjump(); LL state[5]{};dfs(state, n, 1);printf("%d\n", ans);}return 0;
}

http://www.lryc.cn/news/436336.html

相关文章:

  • 萤石举办2024清洁机器人新品发布会 多维智能再造行业标杆
  • 企业级Ansible自动化运维项目案例:实战与技巧
  • JavaSE-易错题集-005
  • 决策树模型的可解释性
  • 2. geoserver 发布postgis数据
  • 【渗透测试】——Brup Suite平台安装
  • redis:全局ID生成器实现
  • jenkins工具的介绍和gitlab安装
  • 【从0开始在CentOS 9中安装Tomcat】
  • 学习Vue3的第五天
  • Python 类中使用 cursor.execute() 时语法错误的解决方法
  • 怎么选择靠谱AI论文生成工具?看完我的试用都会明白!
  • Java 每日一刊(第3期):Hello World
  • git一个项目关联多个远程仓库
  • 衡石分析平台使用手册-部署前准备
  • AI大模型全栈工程师课程笔记 - RAG 检索增强生成
  • 【时时三省】c语言例题----华为机试题<进制转换>
  • 根据NVeloDocx Word模板引擎生成Word(四)
  • C++笔记---stack和queue
  • springboot Rabbit MQ topic 配置文件绑定队列和交换机
  • Visual Studio 2019密钥
  • 【三元组枚举中点】【树状数组】个人练习-Leetcode-1395. Count Number of Teams
  • Anaconda 中遇到CondaHTTPError: HTTP 404 NOT FOUND for url的问题及解决办法
  • 数据库系统 第51节 数据库事务管理
  • 分解+优化+组合+对比!核心无忧!VMD-SSA-Transformer-LSTM多变量时间序列光伏功率预测
  • 二十三种设计模式之建造者模式(类比汽车制造厂好理解一些)
  • macos 系统文件操作时提示 Read-only file system 解决方法
  • 银行业务架构指导应用架构规划及设计方法
  • 最全面IO流介绍
  • fastadmin 文件上传腾讯云