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

网站开发需要多少钱点评网站建设与维护 课件

网站开发需要多少钱点评,网站建设与维护 课件,去国外做赌钱网站,白沙网站建设的目标前言 整体评价 前三题蛮简单的,T4是一个带状态的DP,这题如果用背包思路去解,不知道如何搞,感觉有点头痛。所以最后还是选择状态DP来求解。 欢迎关注 珂朵莉 牛客周赛专栏 珂朵莉 牛客小白月赛专栏 A. 游游的整数翻转 这题最好…

前言

alt


整体评价

前三题蛮简单的,T4是一个带状态的DP,这题如果用背包思路去解,不知道如何搞,感觉有点头痛。所以最后还是选择状态DP来求解。


欢迎关注

珂朵莉 牛客周赛专栏

珂朵莉 牛客小白月赛专栏


A. 游游的整数翻转

这题最好是用API来处理,这样更简洁且准确率高

import java.io.BufferedInputStream;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(new BufferedInputStream(System.in));String s = sc.next();int k = sc.nextInt();String s1 = s.substring(0, k), s2 = s.substring(k);Long r = Long.valueOf(new StringBuilder(s1).reverse().append(s2).toString());System.out.println(r);}}

B. 游游的排列统计

很有意思的一道题

这题甚至可以用状压DP求解

不过这边还是用暴力dfs, 其一,n<10, 其二,约束强,剪枝大

import java.io.BufferedInputStream;
import java.util.Scanner;public class Main {static boolean[] primes = new boolean[20];static {primes[2] = true;primes[3] = true;primes[5] = true;primes[7] = true;primes[11] = true;primes[13] = true;primes[17] = true;primes[19] = true;}static long dfs(int n, int u, int s) {if (s == ((1 << n) - 1)) {return 1;} else {long res = 0;for (int i = 1; i <= n; i++) {if (((1 << (i - 1)) & s) != 0) continue;if (primes[u + i]) continue;res += dfs(n, i, s | (1 << (i - 1)));}return res;}}public static void main(String[] args) {Scanner sc = new Scanner(new BufferedInputStream(System.in));int n = sc.nextInt();long res = 0;for (int i = 1; i <= n; i++) {res += dfs(n, i, 1 << (i - 1));}System.out.println(res);}}

C. 游游刷题

同余分组计数

然后贪心分类讨论

  • r = 0, 则单独为一组 cnt(0)
  • 2 * r = k, 则为 cnt® / 2
  • r < k, 则 min(cnt®, cnt(k - r))

累加即可

import java.io.*;
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(new BufferedInputStream(System.in));int n = sc.nextInt();int k = sc.nextInt();Map<Integer, Integer> hash = new HashMap<>();for (int i = 0; i < n; i++) {int v = sc.nextInt();hash.merge(v % k, 1, Integer::sum);}long ans = 0;for (Map.Entry<Integer, Integer> kv : hash.entrySet()) {int k1 = kv.getKey(), v1 = kv.getValue();if (k1 == 0) {ans += v1;} else if (k1 * 2 == k){ans += v1 / 2;} else if (k1 * 2 < k) {int v2 = hash.getOrDefault(k - k1, 0);ans += Math.min(v2, v1);}}System.out.println(ans);}}

D. 游游买商品

状态DP

令 dp[i][j][s], i为前i个项,j表示使用了多少钱,s为0,1表示状态

0表示 第i项不购买,或者半价购买

1表示 第i项全价购买

那状态转移为

dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j - cost[i] / 2][1] + happy[i]);

dp[i][j][1] = max(dp[i - 1][j - cost[i]][0], dp[i - 1][j - cost[i]][1]) + happy[i];

最后的结果为 max(dp[n - 1][j][s]), 0<=j<=x, s=0,1

import java.io.BufferedInputStream;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(new BufferedInputStream(System.in));int n = sc.nextInt(), x = sc.nextInt();int[] cost = new int[n];long[] happy = new long[n];for (int i = 0; i < n; i++) {cost[i] = sc.nextInt();}for (int i = 0; i < n; i++) {happy[i] = sc.nextLong();}// *)long inf = Long.MIN_VALUE / 10;long[][][] opt = new long[n][x + 1][2];for (int i = 0; i < n; i++) {for (int j = 0; j <= x; j++) {opt[i][j][0] = opt[i][j][1] = inf;}}long ans = 0;if (cost[0] <= x) {opt[0][cost[0]][1] = happy[0];}opt[0][0][0] = 0;for (int i = 1; i < n; i++) {for (int j = 0; j <= x; j++) {opt[i][j][0] = Math.max(opt[i - 1][j][0], opt[i - 1][j][1]);if (j - cost[i] / 2 >= 0) {opt[i][j][0] = Math.max(opt[i][j][0], opt[i - 1][j - cost[i] / 2][1] + happy[i]);}if (j - cost[i] >= 0) {opt[i][j][1] = Math.max(opt[i - 1][j - cost[i]][0], opt[i - 1][j - cost[i]][1]) + happy[i];}}}for (int j = 0; j <= x; j++) {ans = Math.max(ans, opt[n - 1][j][0]);ans = Math.max(ans, opt[n - 1][j][1]);}System.out.println(ans);}}

写在最后

alt

http://www.yayakq.cn/news/287243/

相关文章:

  • 图片上传网站源码网站推广办法
  • 南海网站建设哪家好品牌推广和市场推广的区别
  • 如何提升网站权重子域名网站二级
  • 邯郸网站建设外包做雨棚的网站
  • 如何制作公司网站买个天猫店多少钱一个
  • 网站的设计思想设计公司网站设计详情
  • asp网站做seo安徽省城乡建设信息网
  • 响应式网络网站源码网站空间租用和自己搭建服务器
  • 国内做的比较好的二手网站服务器网站建设教程视频
  • 响应式网站 有哪些弊端网站现在一般做多大尺寸
  • 为何建设银行的网站登不上去淮南建筑网
  • 网站开发费用预算关于宠物的网页设计
  • c 做网站 知乎网站建设企业建站方案
  • 落实网站建设培训班精神公司网站域名如何续费
  • 民营建筑网站软文推广收费
  • 做外汇哪个网站看外国消息微信公众号开发需要什么技术
  • 中国建设交易信息网站襄阳购物网站开发设计
  • 沧州 网站建设微信息公众平台微网站建设
  • 关键词挖掘机爱站网网站搜索页面设计
  • 网站弹窗代码提供o2o网站建设
  • 中山精品网站建设讯息网站seo优化要懂得做微调
  • 百度免费发布信息网站云适配 网站
  • 深色大气网站模板搜索引擎网站模板
  • wordpress支付宝支付宝sem和seo是什么
  • 陕西住房和城乡建设厅网站6wordpress 更新 固定链接
  • wordpress 移动主题南阳网站推广优化公司哪家好
  • 广州网站设计公司排名上海自主建站模板
  • 网站开发时如何兼容百度一下点击搜索
  • 泉州(晋江)网站建设公司建推广网站多少钱
  • mip手机网站模板网站对网络营销的作用