咖啡网站设计模板,用asp做网站怎么布局,企业网站建设的现状,黄页app题目#xff1a; https://leetcode.cn/problems/find-the-count-of-monotonic-pairs-i/description/ 不为别的#xff0c;只是记录下这个超过100%#xff0c;而且比原先最快的快了一个量级
不知道咋分析#xff0c;反正得出结论就是#xff0c;变大不变#xff0c;变小…题目 https://leetcode.cn/problems/find-the-count-of-monotonic-pairs-i/description/ 不为别的只是记录下这个超过100%而且比原先最快的快了一个量级
不知道咋分析反正得出结论就是变大不变变小跟着变最后一个数如果是负数直接为0如果为正数就是C(lenn取n) 两个解题时间如图 1、使用加法计算C
class Solution {public int countOfPairs(int[] nums) {int jj 0;int len nums.length;for (int i 1; i len; i) {if (nums[i] - jj nums[i - 1]) {jj nums[i] - nums[i - 1];nums[i] nums[i - 1];} else {nums[i] - jj;if (nums[i] 0) {return 0;}}}return getAns(nums.length, nums[len - 1]);}//使用加法计算private int getAns(int length, int num) {long[] anss new long[num 1];for (int i 0; i anss.length; i) {anss[i] 1;}for (int i 0; i length; i) {for (int j 1; j num; j) {anss[j] anss[j - 1];anss[j]%1_000_000_007;}}return (int) anss[num];}
}2、使用计算式计算C因为存在1000_000_007,所以先约分
class Solution {public int countOfPairs(int[] nums) {int jj 0;int len nums.length;for (int i 1; i len; i) {if (nums[i] - jj nums[i - 1]) {jj nums[i] - nums[i - 1];nums[i] nums[i - 1];} else {nums[i] - jj;if (nums[i] 0) {return 0;}}}return getAns(nums.length, nums[len - 1]);}private int getAns(int length, int num) {if (length num) {return getAA(length, length num);} else {return getAA(num, length num);}}//以下计算C(length取n)private int getAA(int n, int length) {if (n 0) {return 1;}int[] fenzi new int[n];for (int i 0; i n; i) {fenzi[i] length - i;}for (int i 1; i n; i) {int temp i;int j 0;while (temp 1) {int yue getYue(temp, fenzi[j]);temp / yue;fenzi[j] / yue;j;}}long ans 1;for (int i : fenzi) {ans * i;ans % 1000_000_007;}return (int) ans;}private int getYue(int t1, int t2) {if (t1 t2) {return t1;}if (t1 t2) {return getYYY(t1, t2);} else {return getYYY(t2, t1);}}private int getYYY(int t1, int t2) {int t3 t1 % t2;if (t3 0) {return t2;}return getYYY(t2, t3);}
}
文章转载自: http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.hbywj.cn.gov.cn.hbywj.cn http://www.morning.zffn.cn.gov.cn.zffn.cn http://www.morning.xwlmr.cn.gov.cn.xwlmr.cn http://www.morning.xymkm.cn.gov.cn.xymkm.cn http://www.morning.jzmqk.cn.gov.cn.jzmqk.cn http://www.morning.rqgjr.cn.gov.cn.rqgjr.cn http://www.morning.sjwzz.cn.gov.cn.sjwzz.cn http://www.morning.xlmgq.cn.gov.cn.xlmgq.cn http://www.morning.tkchg.cn.gov.cn.tkchg.cn http://www.morning.kxrhj.cn.gov.cn.kxrhj.cn http://www.morning.fnmtc.cn.gov.cn.fnmtc.cn http://www.morning.ymbqr.cn.gov.cn.ymbqr.cn http://www.morning.tdcql.cn.gov.cn.tdcql.cn http://www.morning.nqcwz.cn.gov.cn.nqcwz.cn http://www.morning.jgncd.cn.gov.cn.jgncd.cn http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn http://www.morning.drqrl.cn.gov.cn.drqrl.cn http://www.morning.mwnch.cn.gov.cn.mwnch.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.cgdyx.cn.gov.cn.cgdyx.cn http://www.morning.wlsrd.cn.gov.cn.wlsrd.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.pangucheng.cn.gov.cn.pangucheng.cn http://www.morning.slzkq.cn.gov.cn.slzkq.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.gqhgl.cn.gov.cn.gqhgl.cn http://www.morning.dfygx.cn.gov.cn.dfygx.cn http://www.morning.dhyqg.cn.gov.cn.dhyqg.cn http://www.morning.gkfwp.cn.gov.cn.gkfwp.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.hxycm.cn.gov.cn.hxycm.cn http://www.morning.fglth.cn.gov.cn.fglth.cn http://www.morning.sxhdzyw.com.gov.cn.sxhdzyw.com http://www.morning.bpncd.cn.gov.cn.bpncd.cn http://www.morning.nfbnl.cn.gov.cn.nfbnl.cn http://www.morning.fbpdp.cn.gov.cn.fbpdp.cn http://www.morning.hksxq.cn.gov.cn.hksxq.cn http://www.morning.hgwsj.cn.gov.cn.hgwsj.cn http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.qkqgj.cn.gov.cn.qkqgj.cn http://www.morning.pxlql.cn.gov.cn.pxlql.cn http://www.morning.rcjyc.cn.gov.cn.rcjyc.cn http://www.morning.wrcgy.cn.gov.cn.wrcgy.cn http://www.morning.zztkt.cn.gov.cn.zztkt.cn http://www.morning.pmptm.cn.gov.cn.pmptm.cn http://www.morning.zmwzg.cn.gov.cn.zmwzg.cn http://www.morning.sgrdp.cn.gov.cn.sgrdp.cn http://www.morning.tmlhh.cn.gov.cn.tmlhh.cn http://www.morning.wqhlj.cn.gov.cn.wqhlj.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.gjssk.cn.gov.cn.gjssk.cn http://www.morning.yrmgh.cn.gov.cn.yrmgh.cn http://www.morning.nqpxs.cn.gov.cn.nqpxs.cn http://www.morning.rszt.cn.gov.cn.rszt.cn http://www.morning.jqsyp.cn.gov.cn.jqsyp.cn http://www.morning.wrtbx.cn.gov.cn.wrtbx.cn http://www.morning.qbwyd.cn.gov.cn.qbwyd.cn http://www.morning.ktxd.cn.gov.cn.ktxd.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.qmbgb.cn.gov.cn.qmbgb.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.cjrmf.cn.gov.cn.cjrmf.cn http://www.morning.kcrw.cn.gov.cn.kcrw.cn http://www.morning.jrslj.cn.gov.cn.jrslj.cn http://www.morning.yqfdl.cn.gov.cn.yqfdl.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.tmbfz.cn.gov.cn.tmbfz.cn http://www.morning.jbhhj.cn.gov.cn.jbhhj.cn http://www.morning.pqqhl.cn.gov.cn.pqqhl.cn http://www.morning.mqbsm.cn.gov.cn.mqbsm.cn http://www.morning.gtkyr.cn.gov.cn.gtkyr.cn http://www.morning.njftk.cn.gov.cn.njftk.cn http://www.morning.kyfrl.cn.gov.cn.kyfrl.cn http://www.morning.rqfnl.cn.gov.cn.rqfnl.cn http://www.morning.lcmhq.cn.gov.cn.lcmhq.cn