nyoj VF函数
大意就是: 在1到在10的9次方中,找到各个位数和为固定值s的数的个数,
首先我们确定最高位的个数,为1到9;
以后的各位为0,到9;
运用递归的思想,n位数有n-1位数生成
f(n)(s) +=f(n-1)(s-k)(k=0~9)
可以学习背包问题,直接降到一维表示,注意规划方向,从高到底。
package vf;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n=82;
int dp[]=new int[n];
dp[0]=0;
int total[]=new int[n];
for(int m=1;m<=9;m++)
{
dp[m]=1;
total[m]=1;
}
for(int i1=1;i1<9;i1++)//每次加一位
{
for(int j=n-1;j>=1;j--)
{
int ans=0;
for(int k=0;k<=9&&k<j;k++)
{ ans+=dp[j-k]; }
dp[j]=ans; total[j]+=dp[j]; } } Scanner scn=new Scanner(System.in); while(scn.hasNext())
{ int a=scn.nextInt();
if(a==1)
{
System.out.println(total[a]+1);
}
else
{ System.out.println(total[a]); } } } }
nyoj VF函数的更多相关文章
- nyoj VF
VF 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make ...
- salesforce 零基础学习(六十五)VF页面应善于使用变量和函数(一)常用变量的使用
我们在使用formula或者validation rules等的时候通常会接触到很多function,这些函数很便捷的解决了我们很多问题.其实很多函数也可以应用在VF页面中,VF页面有时候应该善于使用 ...
- salesforce 零基础学习(六十六)VF页面应善于使用变量和函数(二)常用函数的使用
上一篇介绍VF中常用的变量,此篇主要内容为VF页面可以直接使用的函数,主要包括Date相关函数,Text相关函数,Information相关函数以及logic相关函数,其他相关函数,比如math相关函 ...
- GCD nyoj 1007 (欧拉函数+欧几里得)
GCD nyoj 1007 (欧拉函数+欧几里得) GCD 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The greatest common divisor ...
- nyoj 0269 VF(dp)
nyoj 0269 VF 意思大致为从1-10^9数中找到位数和为s的个数 分析:利用动态规划思想,一位一位的考虑,和s的范围为1-81 状态定义:dp[i][j] = 当前所有i位数的和为j的个数 ...
- C++ 全排列函数 nyoj 366
C++ STL中提供了std::next_permutation与std::prev_permutation可以获取数字或者是字符的全排列,其中std::next_permutation提供升序.st ...
- nyoj 269 VF 动规
VF 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make a ...
- nyoj 1007 GCD(数学题 欧拉函数的应用)
GCD 描述 The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b) ...
- nyoj 269——VF——————【dp】
VF 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make ...
随机推荐
- HttpWebRequest中的KeepAlive
一直不是非常理解.NET中HttpWebRequest的KeepAlive属性有何用处,看了这篇文章就清楚了! http://www.cnblogs.com/lwzz/archive/2011/08/ ...
- MySQL基础学习之数据库
创建一个新的数据库 create database 数据库名称; 查看所有数据库 show databases; 删除数据库 drop database 数据库名称
- 特殊的Python
在学习python之前,我也学习过C ,C++ ,Java ,PHP ,javascript,前端也学习过.但是在学习Python的这段时间里,多多少少也感觉到Python在语法方面的不同和特殊性. ...
- opengl多重采样
效果图如下,两幅图效果是一样的,只是换了个背景.两幅图均是左侧使用了多重采样,右侧的没有使用多重采样.
- Makefile 多目录自动编译
适用于多目录结构 C 工程自动编译. makefile 分成三类: 1. 工程根目录 makefile : 这个makefile执行分成两个阶段 a)递归进入每个子目录, 逐个执行子目录里面的 ma ...
- 【spring配置】 一组配置文件引出的问题
applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans x ...
- MINA实战
backlog,放入到acceptor队列中还未处理最大数量: solinger参数,用来说明close之后是否直接关闭:参数越大,等待时间越长. mina中的udp处理,即使对端关闭也会继续传输,但 ...
- 关于 hashCode() 你需要了解的 3 件事
(点击上方公众号,可快速关注) 原文:eclipsesource 译文:ImportNew - 南半球 链接:http://www.importnew.com/16517.html 在 Java 中, ...
- P1631: [Usaco2007 Feb]Cow Party
还是水题,接近于裸的spfa(个人比较喜欢用spfa,dijkstra不太喜欢用),代码附上 ; type link=^node; node=record t,d:longint; f:link; e ...
- IndexedDB 增删改查 简单的库
<!DOCTYPE html> <html> <head> <title></title> <script src="Ind ...