首页 > 其他分享 > How Many O's? UVA - 11038

How Many O's? UVA - 11038

时间:2023-04-19 20:24:57浏览次数:33  
标签:40 int long How 11038 UVA include

写下区间[a,b]的所有数  ,问一共有多少个 0

 

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define int long long
int n,f[40][40][2][2] ;
 vector<int> a;
 
 int dfs(int x,int cnt0,int flg,int lead){
	if(x<0){
		if(lead) return 1; 
		return cnt0;
	}
	if(~f[x][cnt0][flg][lead] && lead==0 &&flg==0) 
		return f[x][cnt0][flg][lead]; 
	
	int end=flg?a[x]:9, t=0;
	for(int i=0;i<=end;i++){
		t+=dfs(x-1,cnt0+(i==0&&lead==0),flg&&i==end,lead&&i==0);
	}
	if(flg==0||lead==0) f[x][cnt0][flg][lead]=t;
	return t;
 }
 int sov(int x){
 	memset(f,-1,sizeof f); 
 	a.clear(); 
 	while(x){
 		a.push_back(x%10);
 		x/=10;
 	}
 	return dfs(a.size()-1,0,1,1);
 }
 signed main(){
 	int a,b;
 	while(cin>>a>>b){
 		if(a==-1&&b==-1) break;
 		cout<<sov(b)-sov(a-1)<<endl;
 	}
 }
 
 
 

 

标签:40,int,long,How,11038,UVA,include
From: https://www.cnblogs.com/towboa/p/17334488.html

相关文章

  • how to inject <class> type in spring
      sample:ClassitemClass;publicClassgetItemClass(){returnitemClass}publicvoidsetItemClass(ClassitemClass){this.itemClass=itemClass;} NowinjectitemClasspropertyinspring:<beanid="shampoo"class="com.test.Product&......
  • Investigating Div-Sum Property UVA - 11361
     定问在[A,B]中,有多少个整数本身能被m整除,各个数位上数字之和也能被m整除?  #include<iostream>#include<cstring>#include<vector>usingnamespacestd;vector<int>a;intm,f[40][105][105][2];intdfs(intx,intv1,intv2,intflg){ if(x<0) retur......
  • What's PLinq? how to use it?
    What'sPLinq?howtouseit?PLinqstandsfor"ParallelLINQ",whichisaparallelimplementationofLINQ(Language-IntegratedQuery)in.NET.ItallowsdeveloperstoperformLINQqueriesinparallelbyautomaticallypartitioningtheinput......
  • UVA11806 Cheerleaders
    你有一个n×m的网格图,现在你要将K个人放在网格中,满足一下条件:网格图的四个边都至少有一个人。每个格子上不能有两个人。每个人必须都有位置。注意:四个角的人可以同时算作在两个边上  容斥原理   J=0时就是allAnswer#include<iostream>#include<cstri......
  • Train the Tesseract OCR engine[how to do]
    TrainingtheTesseractOCRengineisacomplexandtime-consumingprocessthatinvolvesseveralsteps.Hereisanoverviewoftheprocess:Prepareyourtrainingdata:Thisinvolvescollectingalargenumberofimagesandtheircorrespondingtext.Thete......
  • How to improve the accuracy of Tesseract OCR
    Preprocesstheimage:PreprocessinginvolvesapplyingvarioustechniquestotheimagetoenhanceitsqualityandmakeiteasierfortheOCRenginetorecognizethecharacters.Someofthepreprocessingtechniquesinclude:Binarization:Converttheimage......
  • How to fix use the cURL to connect to GitHub with a 443 HTTPS error All In One
    HowtofixusethecURLtoconnecttoGitHubwitha443HTTPSerrorAllInOne#nvm$curl-o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh|bashhttps://github.com/nvm-sh/nvm#installing-and-updatingerrorscurl:(7)Failedtoconnec......
  • Hackers' Crackdown UVA11825
    你需要将n个集合分成尽量多组,使得每一组里面所有集合的并集等于全集  32122022014111013120   f[S]=max(f[S],f[S-j]+1)且j是一个包含所有点的集合#include<iostream>#include<algorithm>#include<cstring>usingname......
  • Robotruck UVA - 1169
    有n个垃圾,第i个垃圾的坐标为(xi,yi),重量为wi。有一个机器人,要按照编号从小到大的顺序捡起所有垃圾并扔进垃圾桶(垃圾桶在原点(0,0))。机器人可以捡起几个垃圾以后一起扔掉,但任何时候其手中的垃圾总重量不能超过最大载重C。两点间的行走距离为曼哈顿距离(即横坐标之差的绝对值加上纵......
  • Add Again UVA - 11076
     defineS,itissumofallpossiblepermutationsofagivensetofdigits.Forexample,ifthedigitsare<123>,thensixpossiblepermutationsare<123>,<132>,<213>,<231>,<312>,<321>andthesumofthemis......